Memory Locality
Memory locality is the principle that programs tend to access data and instructions in patterns that are predictable and optimized for performance.
- It explains how memory access tends to cluster, allowing systems to design caches more efficiently.
- Memory locality is critical for improving performance, as it enables the CPU to retrieve frequently accessed data faster.
- There are three main types of locality: temporal locality, spatial locality, and sequential locality.
- Temporal locality occurs when a program accesses the same memory location repeatedly within a short period.
- This type of locality takes advantage of the tendency to reuse recently accessed data or instructions.
- Example: In a program loop, a counter variable is repeatedly updated and accessed. Since the variable resides in memory, repeated access to it demonstrates temporal locality.