Python Memory Management and Tips Transcripts
Chapter: Course conclusion and review
Lecture: Allocating memory

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Next up, we said We need to talk about allocation. Now, Most people think of
0:03 Python memory Management as cleaning it up,
0:06 but there's also a whole bunch of techniques and heuristics and data structures put together to
0:11 help us allocate memory without fragmentation and so on.
0:14 We started by saying, Look,
0:16 we'll just go ask the operating system through the C API for memory.
0:19 Turns out, we didn't do it that way,
0:21 right? We said, Look,
0:22 there's hardware, yeah, this is what we expected.
0:24 The RAM, the operating system manages the memory associated with every process, down at
0:30 the C-layer, we can allocate memory from the operating systems virtual
0:34 memory it gave us using malloc.
0:36 That's all good. But then there are other layers that Python adds on. The Python's Allocator,
0:42 so PyMem and PyMalloc and all those API's,
0:46 and then for smaller things, that is,
0:48 objects that by themselves are smaller than 512 bytes,
0:52 We also have Pythons Small Object Allocator.
0:55 Remember, Most things that feel like big objects are just a bunch of small objects linked
1:00 together, so there's a good chance that the things you're working with are gonna land
1:04 in this Small Object Allocated world.
1:08 You can actually see the source code that has kind of
1:10 a ASCII art graphic like this at
1:16 Here's a little tiny segment out of as well.
1:19 If you look at the bottom, it says "a fast, special-purpose memory allocater for small blocks, to be used on top
1:24 of a general purpose malloc".
1:26 So this is the Small Object Allocator and friends.