zoukankan      html  css  js  c++  java
  • 内存地址 Memory Management

    Memory Management

    https://docs.python.org/2/c-api/memory.html

    Memory management in Python involves a private heap containing all Python objects and data structures. The management of this private heap is ensured internally by the Python memory manager. The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, preallocation or caching.

    At the lowest level, a raw memory allocator ensures that there is enough room in the private heap for storing all Python-related data by interacting with the memory manager of the operating system. On top of the raw memory allocator, several object-specific allocators operate on the same heap and implement distinct memory management policies adapted to the peculiarities of every object type. For example, integer objects are managed differently within the heap than strings, tuples or dictionaries because integers imply different storage requirements and speed/space tradeoffs. The Python memory manager thus delegates some of the work to the object-specific allocators, but ensures that the latter operate within the bounds of the private heap.

    It is important to understand that the management of the Python heap is performed by the interpreter itself and that the user has no control over it, even if she regularly manipulates object pointers to memory blocks inside that heap. The allocation of heap space for Python objects and other internal buffers is performed on demand by the Python memory manager through the Python/C API functions listed in this document.

    To avoid memory corruption, extension writers should never try to operate on Python objects with the functions exported by the C library: malloc(), calloc(), realloc() and free(). This will result in mixed calls between the C allocator and the Python memory manager with fatal consequences, because they implement different algorithms and operate on different heaps. However, one may safely allocate and release memory blocks with the C library allocator for individual purposes, as shown in the following example:

    w

    import ctypes
    
    w = 'w_python_c'
    print ctypes.cast(id(w), ctypes.py_object).value
    
    print id(w)
    print id(w)
    wuser@ubuntu:~/apiamzpy$ python wrf.py
    w_python_c
    <xml.etree.ElementTree._IterParseIterator object at 0x7fd33214d1d0>
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}AmazonOrderId' at 0x7fd332167910>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}ASIN' at 0x7fd332167a50>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}SellerSKU' at 0x7fd332167a90>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}OrderItemId' at 0x7fd332167ad0>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}Title' at 0x7fd332167b10>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}QuantityOrdered' at 0x7fd332167b50>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}QuantityShipped' at 0x7fd332167b90>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}PromotionIds' at 0x7fd332167bd0>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}OrderItem' at 0x7fd332167a10>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}OrderItems' at 0x7fd332167990>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}ListOrderItemsResult' at 0x7fd3321678d0>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}RequestId' at 0x7fd332167c50>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}ResponseMetadata' at 0x7fd332167c10>)
    ('end', <Element '{https://mws.amazonservices.com/Orders/2013-09-01}ListOrderItemsResponse' at 0x7fd332167890>)
  • 相关阅读:
    printf()函数不能直接输出string类型
    HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest
    计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)
    POJ 1195.Mobile phones-二维树状数组
    HDU 1541.Stars-一维树状数组(详解)
    ACM中常见错误对应表
    HDU 6112.今夕何夕-蔡勒公式 (2017"百度之星"程序设计大赛
    hdu 2126 Buy the souvenirs 二维01背包方案总数
    codevs 1017 乘积最大 dp
    bzoj 2705: [SDOI2012]Longge的问题 欧拉函数
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6802748.html
Copyright © 2011-2022 走看看