Skip to main content
Engineering LibreTexts

7.2: Aggregate Data and Memory Pictures

  • Page ID
    39377
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Recall from chapter 4 (p. 26) that the right-hand side of our memory pictures bore the label “Aggregate data.” You may have anticipated that that’s where the stuff in this chapter will live, and you’re right. But there’s a catch. Remember that variable names live on the lefthand side, and that’s true even if the variable is of an aggregate type! This turns out to be crucially important, so I’m going to make a big deal about it.

    You must draw your memory pictures (either on a whiteboard, or in your head) in a very specific way, and that way is illustrated in Figure 7.2.1.

    Study this picture carefully, and notice several vitally important things. First, all the variable names are on the left-hand side – whether aggregate or not. This is always, always true.

    Second, the actual array, associative array, and table depicted in this diagram are on the right-hand side. The variable name on the left “points to” the data in question with a little arrow. The technical name for this arrow is a pointer or a reference. The rule is simple: each atomic variable (like gpa or course) contains the colored box itself. Aggregate variables (like the other four) contain a pointer to the group of colored boxes.

    clipboard_e80a889784a672a20827666b0bdfa75f6.png

    Figure \(\PageIndex{1}\): Where aggregate data variables – and their variable names – live in memory.

    Finally, mull over the fact that two different variables in this memory picture are pointing to the same thing! (ages and people) Believe it or not, this is a normal occurrence. The consequence is that if Stacey had a birthday, and we increased her age from 19 to 20 in the associative array, both ages and people would automatically see the new value. There is only one copy of that associative array in memory, and both variable names point at it.

    It may seem like I’m being pedantic with this left-side-right-side stuff and all the little arrows. I promise you I’m not. The moment your data analysis program gets even mildly complicated, you will do the wrong thing and get the wrong answers if you don’t think of it exactly like this. So take your time and commit it to memory. (See what I did there?)


    This page titled 7.2: Aggregate Data and Memory Pictures is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Stephen Davies (allthemath.org) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.