PEP 445: background

This commit is contained in:
Victor Stinner 2013-06-18 02:02:27 +02:00
parent 45a9397c0d
commit d52f6c09ed
1 changed files with 14 additions and 7 deletions

View File

@ -409,13 +409,20 @@ whereas the heap is used for small allocations.
The heap is handled by ``brk()`` and ``sbrk()`` system calls on Linux, and is
contiguous. Memory mappings are handled by ``mmap()`` on UNIX and
``VirtualAlloc()`` on Windows, they are discontiguous. Releasing a memory
mapping gives back the memory immediatly to the system. For the heap, memory is
only gave back to the system if it is at the end of the heap. Otherwise, the
memory will only gave back to the system when all the memory located after the
released memory are also released. This limitation causes an issue called the
"memory fragmentation": the memory usage seen by the system may be much higher
than real usage.
``VirtualAlloc()`` on Windows, they may be discontiguous.
Releasing a memory mapping gives back immediatly the memory to the system. For
the heap, memory is only given back to the system if it is at the end of the
heap. Otherwise, the memory will only be given back to the system when all the
memory located after the released memory are also released. To allocate memory
in the heap, the allocator tries to reuse free space. If there is no contiguous
space big enough, the heap must be increased, even if we have more free space
than required size. This issue is called the "memory fragmentation": the
memory usage seen by the system may be much higher than real usage.
CPython has a pymalloc allocator using arenas of 256 KB for allocations smaller
than 512 bytes. This allocator is optimized for small objects with a short
lifetime.
Windows provides a `Low-fragmentation Heap
<http://msdn.microsoft.com/en-us/library/windows/desktop/aa366750%28v=vs.85%29.aspx>`_.