Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Memory Pools

Give Feedback

00:00 Pools are composed of blocks from a single size class. These tall blue rectangles are each a pool. Each pool maintains a doubly-linked list to other pools of the same class size.

00:14 This allows the algorithm to easily find available space for a given block size, even across multiple different pools of the same size class. A usedpools list tracks the status of each pool that is neither full or empty of blocks. When a given block size is requested, the algorithm checks this usedpools list for the list of pools for the block size needed. Pools themselves may be in one of three states: used, full, or empty.

00:46 A used pool has available blocks for data to be stored. A full pool’s blocks are all allocated and contain data. An empty pool has no data stored and can be assigned any size class for blocks when needed. Similar to usedpools, a freepools list keeps track of all the pools in the empty state, but when do empty pools actually get used? Well, assume your code needs an 8-byte chunk of memory.

01:17 If there are no pools in usedpools of the 8-byte size class, a fresh empty pool is initialized to store 8-byte blocks. This new pool then gets added to the usedpools list so it can be used for future requests.

01:32 Say a full pool frees some of its blocks because the memory is no longer needed. That pool would get added back to the usedpools list for its size class.

01:44 The key takeaway is this: pools are containers for blocks of memory, and each one stores a certain size block. Pools of the same size class are linked so they are easily accessible together.

01:57 Python keeps track of these pools by storing them in lists, notably freepools and usedpools, which tell it where to look for these different pools.

Become a Member to join the conversation.