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,
0:04 their job is to manage a bunch of blocks and a given pool always contains blocks of
0:11 the same size. So if Python needs to allocate something that fits into a 16
0:15 byte blocks, it can just go to the pool that contains those and ask for
0:20 it to allocate it, ask for one that has some free space and so on.
0:23 The pool size is typically set to match the memory page so it maps well to
0:29 RAM, it doesn't get fragmented, and pythons ability to reuse this fixed,
0:35 contiguous set of memory helps reduce fragmentation that would otherwise happen if we just went to
0:40 the underlying C-layer and just said
0:42 "give me the next free bit of memory that you have of this size".
0:46 You can look at this a little bit
0:47 here is the source code around the pools.
0:49 It has the next free block. Right
0:51 there is a pointer that you can always get you,
0:53 and it also has the next pool and the previous pool.
0:57 So it's kind of a doubly-linked list of pools
1:01 that within there contain a bunch of these blocks.