python如何对内存管理_Python内存管理是如何工作的?

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值