python 內(nèi)存接口分層圖
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.
大內(nèi)存分配使用raw memory
小內(nèi)存使用arenas 內(nèi)存池管理
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
You can get allocations statistics by calling
sys._debugmallocstats()
PYTHONMALLOCSTATS
使用 環(huán)境變量PYTHONMALLOCSTATS=true