美文网首页
python 内存管理

python 内存管理

作者: lmy_8db4 | 来源:发表于2018-12-03 15:21 被阅读0次

    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

    相关文章

      网友评论

          本文标题:python 内存管理

          本文链接:https://www.haomeiwen.com/subject/ikgmcqtx.html