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,
0:01 let's go explore. Over here, I'd like to enter that link bit.ly/cpythonlong
0:07 and it'll redirect us over to this horrible url,
0:10 which you can see now why I was using Bitly to shorten it.
0:13 This is, in the Python organization,
0:15 the CPython project in the longobject.c file,
0:21 and this is the PyObject
0:23 PyLong_FromLong, and you can just go through and you can see all the stuff that's
0:27 happening that's going on here. So there's all the stuff I deleted we're still in
0:30 the same function and still in the same function.
0:35 When are we done? Goes for aways.
0:38 There's quite a bit going on here.
0:41 Let's go to the top. You can see that this is the long,
0:44 arbitrary precision integer object implementation. And in this objects section,
0:51 you'll see all different sorts of things,
0:53 like Booleans, and then you've got dictionaries,
0:58 here's part of the dictionary implementation.
1:01 There's the allocation stuff. obmalloc.
1:04 Here's the base PyObject.
1:07 Um, yup, PyObject pointers all over the place,
1:10 Right? This thing. So this is the implementation for that and one thing that's interesting
1:15 is, you would think just the base class would be pretty simple,
1:18 but it's 2000 lines long, like the header file.
1:22 The header file, if you go up,
1:23 is already, I think, like 600 lines long.
1:25 So there's a lot of stuff going on with every one of these objects,
1:30 and throughout various places in the course,
1:32 I'll be giving you the short your url's,
1:34 which will take you to different locations in the source code.
1:37 You don't have to go look at it,
1:38 especially if all the code here makes your eyes water.
1:42 That's fine. You don't have to look at it.
1:43 But this is where you can go and see exactly what is happening and when or
1:48 what kind of data is being stored and what structure and how the runtime is using
1:53 that to manage the memory or allocate things and so on.