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>)
  • 相关阅读:
    Delphi如何处理在进行大量循环时,导致的应用程序没有响应的情况
    [转]:Delphi 中的哈希表(1): THashedStringList
    C# 计算两个字符串的相似度
    中文字号VS英文字号(磅)VS像素值
    在C#中如何将多个rtf文件内容组合在一起用一个rtf文件保存?
    C#中用RichTextBox实现图文混排和保存的例子
    ISE MAP报错: Unsupported programming for BSCAN block and JTAG_CHAIN attribute value 1的解决方法
    [转]matlab如何复制spectrum scope的图
    iMpACT中的Xilinx Prom烧录
    【verilog】fdisplay中如何保存有符号形式
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6802748.html
Copyright © 2011-2022 走看看