Questions: Memory Hierarchy

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer writes a loop that iterates through a million-element array in order, processing each element once. Why does this run much faster than code that accesses the same million elements in random order?

ASequential access allows the OS to allocate more RAM to the process
BSequential access exhibits spatial locality — hardware automatically loads nearby array elements into cache together, so most accesses are cache hits
CThe CPU pipeline handles sequential instructions more efficiently than branching code
DRandom access requires the garbage collector to run more frequently
Question 2 Multiple Choice

A programmer wants critical data loaded into L1 cache to guarantee fast access. They look for an instruction to explicitly place a specific variable in L1 cache. Why won't they find one?

AL1 cache is too small to store user-specified variables
BCache placement is managed automatically by hardware, not by programmer instructions
CVariables cannot be stored in cache — only machine instructions can
DOnly the operating system has permission to write to cache
Question 3 True / False

A cache miss means the requested data is lost and is expected to be recomputed or re-fetched from disk.

TTrue
FFalse
Question 4 True / False

Registers are faster than L1 cache, and DRAM is slower than L3 cache but faster than secondary storage such as an SSD.

TTrue
FFalse
Question 5 Short Answer

What are temporal locality and spatial locality, and why are they the reason the memory hierarchy works effectively rather than merely adding expensive storage layers?

Think about your answer, then reveal below.