Memory Diagrams in CS 70
Why?
The ability to do "creative" things with memory means that we need a careful way to track what's happening in memory during the run of our C++ programs.
To help us build the right mental model for what's going on and reason about our code (and to show that we have the right model), in CS 70 we draw memory diagrams to represent program state. We'll start with a simple diagrammatic model in this lesson. Over the course of the next few weeks, we'll expand our model to include different aspects of the C++ language.
How?
Here's how we'll model the variable created with the declaration int x = 3
:
Note that because we don't know where in memory x
will end up (although we know it will be somewhere!), we're using the name M01
to stand in for the actual location of x
.
Things to Notice
The diagram is drawn so that only information that's stored in memory during the run of our program is inside the box. Information that is not stored in memory during the run of our program is outside the box.
(When logged in, completion status appears here.)