Memory Blocks
00:00
Pools contain blocks of memory, which can be allocated as your program needs them. Each block can be in one of three states: untouched, free, or allocated. untouched is memory that has not been allocated. free blocks used to be allocated, but were then freed by CPython because they were no longer needed. When CPython frees memory, it doesn’t get handed back over to the OS. As you can see, it remains owned by CPython, but it’s now marked as free so it can be used again later. Finally, allocated blocks were allocated and store some data.
00:40
A freeblock pointer points to a singly-linked list containing all the free blocks of memory. A linked list is used because these free blocks may not be contiguous, or near each other. As you can see, these free blocks are scattered between two different usedpools.
00:59
free blocks are prioritized by the allocation algorithm. If not enough free blocks are available, it resorts to allocating some untouched blocks.
01:10
As the memory manager frees memory, its blocks go from an allocated state to a free state. They are then added to the front of the free blocks list.
Become a Member to join the conversation.