Python Memory Management and Tips Transcripts
Chapter: Allocating memory in Python
Lecture: Allocation pools
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
The next level up in this algorithm are the pools. Now pools, their job is to manage a bunch of blocks and a given pool always contains blocks of
0:12
the same size. So if Python needs to allocate something that fits into a 16 byte blocks, it can just go to the pool that contains those and ask for
0:21
it to allocate it, ask for one that has some free space and so on. The pool size is typically set to match the memory page so it maps well to
0:30
RAM, it doesn't get fragmented, and Pythons ability to reuse this fixed,
0:36
contiguous set of memory helps reduce fragmentation that would otherwise happen if we just went to the underlying C-layer and just said
0:43
"give me the next free bit of memory that you have of this size". You can look at this a little bit here is the source code around the pools.
0:50
It has the next free block. Right there is a pointer that you can always get you, and it also has the next pool and the previous pool.
0:58
So it's kind of a doubly-linked list of pools that within there contain a bunch of these blocks.