Memory Hierarchy

Which is the best example of temporal locality?

  1. AReading each element of an array once, from start to end
  2. BUpdating the same sum variable many times inside a loop
  3. CReading data at a random address only once each time
Show answer and explanation

Answer: B. Updating the same sum variable many times inside a loop

Temporal locality is the tendency to reuse data soon after using it, and a variable read and written repeatedly inside a loop is the classic example. Such data is reused while still in the cache or registers, so accesses are fast. Reading an array from start to end is an example of spatial locality, using nearby addresses in succession, which is a different property. Reading random addresses once each has almost no locality of either kind.

  • A. Reading in order from the start is an example of spatial locality.
  • B. Correct. Using the same variable many times in a short span is temporal locality.
  • C. Reading random addresses once each has almost no locality.
Practice this topic Back to topic

More Memory Hierarchy questions

  1. Scanning the 2D C array a[i][j] with j in the inner loop, as above, tends to be faster than with i in the inner loop. Why?
  2. For a direct-mapped cache with 32-bit addresses, 32 KB capacity and 64-byte lines, how many tag bits are there?
  3. How many sets does a 4-way set-associative cache with 32-bit addresses, 32 KB capacity and 64-byte lines have?
  4. In a fully associative cache, how many address bits are used for the index (the part that selects a set)?
  5. With an L1 hit time of 1 ns and miss rate of 5%, an L2 hit time of 10 ns and local miss rate of 20%, and main memory access time of 100 ns, what is the average memory access time?