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>)

内存地址 Memory Management的更多相关文章

  1. SQL Server 2012 内存管理 (memory management) 改进

    SQL Server 2012 的内存管理和以前的版本相比,有以下的一些变化. 一.内存分配器的变化 SQL Server 2012以前的版本,比如SQL Server 2008 R2等, 有sing ...

  2. Objective-C Memory Management Being Exceptional 异常处理与内存

    Objective-C Memory Management    Being Exceptional  异常处理与内存 3.1Cocoa requires that all exceptions mu ...

  3. Memory Management in Open Cascade

    Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...

  4. Memory Translation and Segmentation.内存地址转换与分段

    原文标题:Memory Translation and Segmentation 原文地址:http://duartes.org/gustavo/blog/ [注:本人水平有限,只好挑一些国外高手的精 ...

  5. Objective-C Memory Management 内存管理 2

    Objective-C Memory Management 内存管理  2  2.1 The Rules of Cocoa Memory Management 内存管理规则 (1)When you c ...

  6. Objective -C Memory Management 内存管理 第一部分

    Objective -C Memory Management  内存管理  第一部分 Memory management is part of a more general problem in pr ...

  7. [译]C# 7系列,Part 10: Span<T> and universal memory management Span<T>和统一内存管理

    原文:https://blogs.msdn.microsoft.com/mazhou/2018/03/25/c-7-series-part-10-spant-and-universal-memory- ...

  8. Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2

    from: http://www.raizlabs.com/dev/2014/04/hunting-your-leaks-memory-management-in-android-part-2-of- ...

  9. Android内存管理(1)WRANGLING DALVIK: MEMORY MANAGEMENT IN ANDROID PART 1

    from : http://www.raizlabs.com/dev/2014/03/wrangling-dalvik-memory-management-in-android-part-1-of-2 ...

随机推荐

  1. Python基础编程闭包与装饰器

    闭包的定义 闭包是嵌套在函数中的函数. 闭包必须是内层函数对外层函数的变量(非全局变量)的引用. 闭包格式: def func(): lst=[] def inner(a): lst.append(a ...

  2. BZOJ 1906. 树上的蚂蚁

    传送门 发现蚂蚁不多,所以考虑两两枚举然后判断 那么首先要求出两条链的公共部分,然后根据之间在公共链的时间段和是同向还是反向进行判断 思路简单但是细节很多...... 首先求链的公共部分,设两种蚂蚁为 ...

  3. 【nginx】上传文件error报413 Request Entity Too Large

    nginx配置增大上传文件限制 如果访问地址是通过nginx转发配置的 server{ ... ... client_max_body_size 50M; ... ... } ingress配置增大上 ...

  4. Red Hat Enterprise Linux查看系统版本命令

    # arch 返回结果为i686表示32位系统,x86_64表示64位系统. # uname -a # uname -r # lsb_release -a # cat /proc/version # ...

  5. 浅析DES、AES、RSA、MD5加密算法及其应用场景

    对称加密算法DES 算法:一种典型的块加密方法,将固定长度的明文通过一系列复杂的操作变成同样长度的密文,块的长度为64位.同时,DES 使用的密钥来自定义变换过程,因此算法认为只有持有加密所用的密钥的 ...

  6. vps(windows2003)安全设置参考

    一.禁止默认共享 建立一个记事本,填上以下代码.保存为 “删除默认共享.bat”并加到启动项目中 net share c$ /del net share d$ /del net share e$ /d ...

  7. 2019-8-31-MobaXterm-使用代理

    title author date CreateTime categories MobaXterm 使用代理 lindexi 2019-08-31 16:55:58 +0800 2018-02-13 ...

  8. FPGA引脚锁定 注意err和高阻状态

    1.fpga没有用的的管脚一定要设置成高阻状态设置路径如下: Assignmen->Device->Device&Pin Option->Unused pins->As ...

  9. 通过关键字Event定义用户自己的事件

    Event 语句 定义用户自定义的事件. 语法[Public] Event procedurename [(arglist)] Event 语句包含下面部分: 部分 描述 Public 可选的.指定该 ...

  10. 02 getsockopt

    #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> int getsockopt(int sockfd ...