内存地址 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>)
内存地址 Memory Management的更多相关文章
- SQL Server 2012 内存管理 (memory management) 改进
SQL Server 2012 的内存管理和以前的版本相比,有以下的一些变化. 一.内存分配器的变化 SQL Server 2012以前的版本,比如SQL Server 2008 R2等, 有sing ...
- Objective-C Memory Management Being Exceptional 异常处理与内存
Objective-C Memory Management Being Exceptional 异常处理与内存 3.1Cocoa requires that all exceptions mu ...
- Memory Management in Open Cascade
Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...
- Memory Translation and Segmentation.内存地址转换与分段
原文标题:Memory Translation and Segmentation 原文地址:http://duartes.org/gustavo/blog/ [注:本人水平有限,只好挑一些国外高手的精 ...
- Objective-C Memory Management 内存管理 2
Objective-C Memory Management 内存管理 2 2.1 The Rules of Cocoa Memory Management 内存管理规则 (1)When you c ...
- Objective -C Memory Management 内存管理 第一部分
Objective -C Memory Management 内存管理 第一部分 Memory management is part of a more general problem in pr ...
- [译]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- ...
- 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- ...
- 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 ...
随机推荐
- Luogu P1864 [NOI2009]二叉查找树
题目 \(v\)表示权值,\(F\)表示频率. 首先我们显然可以把这个权值离散化. 然后我们想一下,这个东西它是一棵树对吧,但是我们改变权值会引起其树形态的改变,这样很不好做,所以我们考虑把它转化为序 ...
- Mysql中explain作用详解
一.MYSQL的索引 1.索引(Index):帮助Mysql高效获取数据的一种数据结构.用于提高查找效率,可以比作字典.可以简单理解为排好序的快速查找的数据结构.2.索引的作用:便于查询和排序(所以添 ...
- 高性能迷你React框架anujs1.1.3发布
anujs现在只差一个组件(mention)就完全支持阿里的antd UI库了.一共跑通346个测试, 应该是全世界最接近官方React的迷你框架了. 以后的工作就是把React16的一些新特性支持了 ...
- Redux 关系图解
Redux是一款状态管理库,并且提供了react-redux库来与React亲密配合, 但是总是傻傻分不清楚这2者提供的API和相应的关系.这篇文章就来理一理. Redux Redux 三大核心 Re ...
- spring boot 枚举使用的坑2
上一篇说到在枚举当在controller的方法做参数时的坑,解决方法是配置了一个converter,后来想想,如果不闲每次都加一个注解麻烦的话,可以在参数前面加一个注解,添加一个解析器应该也可以解决这 ...
- 39. Combination Sum (Java)
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), fin ...
- apply_nodes_func
import torch as th import dgl g=dgl.DGLGraph() g.add_nodes(3) g.ndata["x"]=th.ones(3,4) #n ...
- mysql的索引以及优化
本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群: 281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...
- vue组件样式scoped
1.vue组件中的样式如果没加scrped,样式代表的是全局样式(避免组件之间样式的冲突).加了属性代表是模块化的. 其他组件引用button组件 上面分析了单个组件渲染后的结果,那么组件互相调用之后 ...
- [原创]Laravel 基于redis队列的解析
目录 参考链接 本文环境 为什么使用队列 Laravel 中的队列 分发任务 任务队列 Worker Last-Modified: 2019年5月10日11:44:18 参考链接 使用 Laravel ...