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

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands 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 your subtitle preferences 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 refer to our video player troubleshooting guide for assistance.

Memory Pools

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.