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.
-
大内存分配使用raw memory
-
小内存使用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.pngAllocation statistics
-
You can get allocations statistics by calling
sys._debugmallocstats()
-
PYTHONMALLOCSTATS
使用 环境变量PYTHONMALLOCSTATS=true
网友评论