Python Memory Management and Tips Transcripts
Chapter: Allocating memory in Python
Lecture: Pools in the CPython source
0:00 Let's go back to the CPython source code and look at this idea of
0:03 blocks, pools, and arenas. We haven't talked about arenas yet,
0:06 but let's just look over there real quick.
0:08 So I've come up with another Bitly URL for you,
0:10 cause like, all of these are super long.
0:12 So "biy.ly/cpythonpools", if you want to go there, and you
0:17 might be surprised to see what you get when you come here.
0:19 You don't get source code immediately.
0:22 There is source code if you scroll enough, like here,
0:25 there's some source code, but check this out.
0:28 There's like a full on essay about what is happening around one of these pools.
0:33 Okay, so if we go down a little bit
0:34 further, it talks about how blocks are managed within the pools.
0:38 So blocks in the pools are getting carved out as needed.
0:41 The free block points to the start of a linked list of the free block,
0:46 so you can always just go there and start allocating into that one.
0:50 So pretty awesome, right? There's a bunch of stuff about,
0:53 like things that they're doing that might be a little bit obscure, or what's unclear,
0:57 and so why it's happening that way and so on.
1:00 So when I was studying this I
1:02 Was really surprised at the level of detail,
1:04 describing how pools and blocks interact together.
1:08 And if you want to see what the core developers and the
1:11 people who worked on this and implement it and maintain it,
1:14 what they say, Well, here it is,
1:16 right in the source code on GitHub.