What is 'Memory Locality' (Spatial and Temporal)?

What is 'Memory Locality' (Spatial and Temporal)?

Approach: Describe how computer systems optimize access to recently used or nearby data.

Temporal locality: if a memory location is referenced, it is likely to be referenced again soon. Spatial locality: if a memory location is referenced, nearby locations are likely to be referenced soon.

Follow-up: How do arrays leverage spatial locality?

Key concepts: cache lines, l1/l2/l3 cache, registers.