Locality of reference is when a processor access the same set of memory over a relatively short period of time.

  • Also known as Principle of locality

Spatial locality

Reuse of data that is stored relatively close to each other.

A memory location is considered to be of spatial locality, then its nearby memory locations will be accessed again; generally it’s a good idea to judge the size and shape of nearby memory regions around the current reference to prepare for faster access.

  • A good example is data that is arranged and accessed linearly; like an 1D array

Temporal locality

Reuse of specific data, resources or a set of instructions over a relatively small period of time.

If something has temporal locality, then it is likely to be accessed again in the near future.

  • Common to try and store heavily referenced data in faster memory

Temporal locality can also lead to spatial locality, if the target memory location is close to the current memory location.