Python Memory Management and Tips Transcripts
Chapter: Python variables and memory
Lecture: Passing values in C

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's look at one more example before we move on to talk about how Python does the equivalent thing. So let's look at a slight variation.
0:08 We've got the same SamePerson function. It's going to take two people and determine if they're the same.
0:15 However, this time, instead of passing pointers, which are basically numbers to memory addresses where the real data lives,
0:21 we're just gonna pass the id's. Remember before we're saying p1 arrow, id. Might as well just past the id that makes it a little easier to do.
0:29 So we have our two pieces of data which are integers p1_id and p2_id. They don't point anywhere. They literally just have the value,
0:38 right? This is the same thing that was the id before. So in C, we can pass the value of a thing or we can pass
0:45 a pointer like we saw before and there's good reason for both. If you have a large data structure and you want to move it around without making copies
0:53 because that would be slow, You would pass by reference or pass a pointer. If you wanted to,
0:59 even more importantly, you want to make changes to it and have those changes reflected in other parts of the program,
1:04 you need to pass the pointer, change the shared location, and then everyone will see those changes. As opposed to here if we change the id
1:12 only this function would see it. But, C and many languages, c#, other languages, they have this distinction between passing sometimes just the value,
1:21 like the integers, and sometimes like previously the address of the thing that you gotta follow as a pointer out there.
1:28 So, I want to put these two up and contrast them for you, and then we're gonna dive into Python.

Talk Python's Mastodon Michael Kennedy's Mastodon