CS 70

Objects in Our Memory Model

  • Duck speaking

    How would we draw an object in our memory model?

  • LHS Cow speaking

    Oh, yeah! Good question!

  • RHS Cow speaking

    Let's look at the stack after the first two lines of the main function in main.cpp.

...
int main() {
    Cow bessie{3, 12};
    const Cow mabel{1, 2};

...

When it's important to keep track of the values of the member variables, we can draw objects as groupings of variables, which is basically how objects are actually arranged in memory! When you allocate space for an object, you are actually allocating space for all of its member variables (and a few more bookkeeping things that we won't bother to model).

As we have in the past, sometimes we will work with examples where the details of what's inside the object don't really matter.

In that case we can just draw the object abstractly as below, leaving out the specific member variables.

(When logged in, completion status appears here.)