A magazine about programmers, code, and society. Written by and for humans since 2018.

Ryan Baker

The filmography of Christopher Nolan runs along a common thread: a never-ending obsession with human memory. In “Memento” (2000), Leonard Shelby must solve the horrendous rape and murder of his wife while dealing with short-term memory loss. In “The Prestige” (2006), memory is self-deception. Dom Cobb, in “Inception” (2010), keeps building an emotional and subjective reality around the souvenir of his wife. Cooper’s memory in “Interstellar” (2014) is non-linear, and oblivious to time dilation issues. “Tenet” (2020) opposes the existence of our memory to our capacity for free will. Finally, “Oppenheimer” (2023) gives a moral perspective through the regretful memory of building the ultimate weapon. Nolan screams at us that human memory is non-linear, repetitive, unreliable, and most importantly, in a perpetual conflict with that thing we call reality.

In many ways, our trust around computers stems from their capacity to remember things with uncanny levels of detail, unprecedented in human history; a computer should not be in conflict with reality. It is at this point that software developers must learn at all costs to manage whatever memory (nowadays, tens of gigabytes thereof) available to our programs. These should not forget; our operating systems must do everything in their power to remember, everything and anything, at all times.

But the truth is that computer memory, referred to as “storage” in ancient times (read: 1945 to the 1980s) is a hard beast to grasp, particularly for self-taught programmers like the one writing these lines. Understanding the architecture of computer memory is tantamount to be able to prevent computer security issues stemming from stack overflows; to understand performance drops due to intensive copying; and to reduce the resource requirements of our software, even in times like these when 16 GB is a common amount of RAM for any personal computer.

It is precisely in this situation that this month’s Vidéothèque movie hits a chord: “Memory Segments in C/C++”, by Ryan Baker, provides a simple visual artifact to understand the major segments into which the memory of a C program is divided, or, as the author calls it, its “anatomy”.

Not only that, but this simple video provides the required animation bits to understand how memory evolves throughout the runtime of a program, with the various segments growing and decreasing accordingly. The author maps these visual cues into bits of assembly and C code, showing where the different variables are allocated (and why), and how the memory layout changes through reads and writes, including an animation showing stack frames come and go while the program enters and exits functions and procedures.

In my personal work as a trainer for future iOS mobile application developers, back in the days when Swift did not exist yet, and the platform was all about Objective-C, the explanation of memory layouts and the differences between stack and heap was one of the highlights of my courses. I always took the time to explain this particular point at the very beginning of my sessions, particularly when teaching in front of an audience consisting of developers solely equipped with web programming experience.

This month’s video is then, all things considered, a simple, short, and very useful movie that is strongly recommended for any (self-taught or not) programmer who is curious and eager to understand how the C and C++ programming languages manage memory. These concepts, however, and needless to say, are also fundamental for those using any other language, be it JavaScript, Python, Java, or Go.

But to be honest, this short video (it is not even 5 minutes long) is by no means enough to understand all the intricacies of the subject of memory management. If your goal is to achieve a deeper understanding, and how to use that knowledge in your daily programming tasks, you might want to read this month’s Library issue. You will thank us later.

Watch this month’s (admittedly short) Vidéothèque movie, “Memory Segments in C/C++”, by Ryan Baker, on YouTube. Complement it with Ryan’s previous video titled “Understanding Static in C++”. Contrary to what Nolan depicts in his productions, our programs should never worry about memory loss, non-linearity, or hallucinations–the latter being a concern that LLM creators, sadly, do not seem to care about.

Cover snapshot chosen by the author.

Back to top