The Memory Hierarchy and Why Caching Works · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.
En anglais

Small fast memory, big slow memory

Computing · Computer Systems · ages 18-19
Name ______________________   Date ____________
  1. A loop reads the same lookup entry at address 52 on consecutive iterations. Which locality does this illustrate?

    • Temporal locality
    • Spatial locality
    • No locality
  2. In the typical hierarchy shown, which order has increasing access time, from shortest to longest?

    • Main memory, caches, registers, disk
    • Registers, caches, main memory, disk
    • Disk, main memory, caches, registers
  3. Accessing neighbouring memory locations one after another shows spatial locality.

    Circle one:   True   False

  4. Consecutive one-byte elements occupy addresses 0,1,2,3. A loop reads each once in that order. Which locality does the address pattern illustrate?

    • Spatial locality
    • Temporal locality
    • Neither locality
  5. A row-major two-row, four-column array uses consecutive one-byte elements at addresses 0 through 7. Column-first reads 0,4,1,5,2,6,3,7. Why can this use less of each cache line before eviction on larger arrays?

    • It reads only the first row and skips every cell stored in later rows.
    • It sorts the array before reading any of the values in either row.
    • It jumps between rows before using nearby elements in the same row.
  6. In the lesson's typical hierarchy, a cache has shorter access time than main memory. Which statement about their total capacity is usually true?

    • A cache usually holds more data than main memory.
    • Main memory usually holds more data than a cache.
    • They always hold exactly the same amount of data.
  7. An empty cache holds one aligned 4-byte line. Elements are 1 byte. A reads addresses 16 through 23 in order. B reads 16,20,17,21,18,22,19,23. Both read every element once. How many misses does each have?

    • A: 2; B: 8
    • A: 8; B: 2
    • A: 2; B: 2
  8. A column-major three-row, two-column array stores column 0 at addresses 100,101,102 and column 1 at 103,104,105. A student chooses row-first because rows look shorter. Which correction is sound?

    • Row-first must have fewer misses because the number of drawn columns determines byte order.
    • Both traversals must have identical misses because they visit the same number of elements.
    • Column-first follows neighbours here; the drawing's shape does not determine memory order.
LightMySky · lightmysky.comW1-mt_0f5ArFPlxP-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Small fast memory, big slow memory W1-mt_0f5ArFPlxP-s1

  1. Temporal locality · The loop returns to the same location soon afterwards. That is temporal locality, rather than movement through neighbouring locations.
  2. Registers, caches, main memory, disk · The pictured typical ordering starts with registers, then caches, main memory and disk.
  3. True · Spatial locality concerns nearby locations accessed close together in time. The statement describes that pattern.
  4. Spatial locality · Each address is the next byte in memory. Visiting those neighbours in order illustrates spatial locality.
  5. It jumps between rows before using nearby elements in the same row. · The first move is from address 0 to 4, rather than its neighbour 1. Column-first repeatedly jumps rows; on larger arrays this can delay reuse until a line is evicted.
  6. Main memory usually holds more data than a cache. · In the stated typical hierarchy, capacity increases from caches to main memory. Main memory usually holds more data even though cache access is quicker.
  7. A: 2; B: 8 · The lines contain addresses 16 through 19 and 20 through 23. A misses once per line: 2. B alternates lines on every access, replacing the only resident line each time: 8.
  8. Column-first follows neighbours here; the drawing's shape does not determine memory order. · The stated column-major layout makes each column consecutive. Column-first follows 100 through 105 in order. The drawing's dimensions do not set layout or guarantee miss counts.
Worksheet · LightMySky