python 内存管理

python 内存接口分层图

Raw memory interface -> memory interface (pymalloc allocator) -> object allocators

The pymalloc allocator

Python has a pymalloc allocator optimized for small objects (smaller or equal to 512 bytes) with a short lifetime. It uses memory mappings called “arenas” with a fixed size of 256 KB. It falls back to PyMem_RawMalloc() and PyMem_RawRealloc() for allocations larger than 512 bytes.

  1. 大内存分配使用raw memory

  2. 小内存使用arenas 内存池管理

Arenas and pools

The arena is a chunk of 256kB memory allocated on the heap, which provides memory for 64 pools.

屏幕快照 2018-12-04 下午3.19.30.png

Allocation statistics

  1. You can get allocations statistics by calling sys._debugmallocstats()

  2. PYTHONMALLOCSTATS 使用 环境变量PYTHONMALLOCSTATS=true

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,438评论 0 10
  • python内存管理是通过引用计数来实现的。当对象的引用计数为0时,会被gc回收。 为了探索对象在内存的存储,我们...
    冬季恋歌1218阅读 1,691评论 0 2
  • 在比较浅层次上我们通过说明如下问题来进一步深入了解python内存管理机制:Python中到底是“传引用”还是“传...
    tdeblog阅读 2,507评论 0 0
  • 曾经现在我都是胖子,我不是笨蛋,我不是傻瓜,不是可以被人欺负的胖子,胖子心地善良,胖子亲切和蔼。比瘦子好看多啦。 ...
    蔷薇飒阅读 289评论 0 0
  • ——本文授权自订阅号:复利传说 外围市场不容乐观,A股今日开盘后继续下探,沪指盘中一度跌至2536.67点,刷新近...
    财富指南者阅读 190评论 0 0