Python Memory Management and Tips Transcripts
Chapter: Memory and classes
Lecture: Concept: Properties, a memory-oriented perspective
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
so we saw that many times classes can contain computed fields. They've got base data, or primary data, in this case a and b,
0:10
but then there might be some other fields we want to provide to our users that could be computed, or are derived from, that base
0:18
data. Here, like c is a over B, and d is a times b. Somewhat contrived, but you can see some of this could always like,
0:25
c and d could always be recreated from a and b, but it's handy. It's easy to just make these all fields so people don't have
0:31
to call functions, they can just say a "thing.d" and it's all good. But if we switch this over to properties, from the outside,
0:39
the consumption model feels identical. But from the memory side, we're now using half as much memory,
0:44
or maybe more, depending on what kind of objects we were storing there. So this is really nice and really easy.
0:51
It also provides slots or spaces in the code to do things like cacheing like only
0:57
computed on demand but then don't recompute it and all kinds of interesting stuff along those lines.