Python Memory Management and Tips Transcripts
Chapter: Python variables and memory
Lecture: CPython long source

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, we've taken the red pill, let's go explore. Over here, I'd like to enter that link bit.ly/cPythonlong
0:08 and it'll redirect us over to this horrible url, which you can see now why I was using Bitly to shorten it. This is, in the Python organization,
0:16 the CPython project in the longobject.c file, and this is the PyObject
0:24 PyLong_FromLong, and you can just go through and you can see all the stuff that's
0:28 happening that's going on here. So there's all the stuff I deleted we're still in the same function and still in the same function.
0:36 When are we done? Goes for aways. There's quite a bit going on here. Let's go to the top. You can see that this is the long,
0:45 arbitrary precision integer object implementation. And in this objects section, you'll see all different sorts of things,
0:54 like Booleans, and then you've got dictionaries, here's part of the dictionary implementation. There's the allocation stuff. obmalloc.
1:05 Here's the base PyObject. yup, PyObject pointers all over the place,
1:11 Right? This thing. So this is the implementation for that and one thing that's interesting
1:16 is, you would think just the base class would be pretty simple, but it's 2000 lines long, like the header file. The header file, if you go up,
1:24 is already, I think, like 600 lines long. So there's a lot of stuff going on with every one of these objects,
1:31 and throughout various places in the course, I'll be giving you the short your url's, which will take you to different locations in the source code.
1:38 You don't have to go look at it, especially if all the code here makes your eyes water. That's fine. You don't have to look at it.
1:44 But this is where you can go and see exactly what is happening and when or
1:49 what kind of data is being stored and what structure and how the runtime is using that to manage the memory or allocate things and so on.


Talk Python's Mastodon Michael Kennedy's Mastodon