Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Difference Between Spatial Locality and Temporal Locality

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Prerequisite – Locality of Reference
1. Spatial Locality :
Spatial Locality means that all those instructions which are stored nearby to the recently executed instruction have high chances of execution. It refers to the use of data elements(instructions) which are relatively close in storage locations.

2. Temporal Locality :
Temporal Locality means that a instruction which is recently executed have high chances of execution again. So the instruction is kept in cache memory such that it can be fetched easily and takes no time in searching for the same instruction.



Difference between Spatial Locality and Temporal Locality :

S.No.Spatial LocalityTemporal Locality
1.In Spatial Locality, nearby instructions to recently executed instruction are likely to be executed soon.In Temporal Locality, a recently executed instruction is likely to be executed again very soon.
2.It refers to the tendency of execution which involve a number of memory locations .It refers to the tendency of execution where memory location that have been used recently have a access.
3.It is also known as locality in space.It is also known as locality in time.
4.It only refers to data item which are closed together in memory.It repeatedly refers to same data in short time span.
5.Each time new data comes into execution.Each time same useful data comes into execution.
6.Example :
Data elements accessed in array (where each time different (or just next) element is being accessing ).
Example :
Data elements accessed in loops (where same data elements are accessed multiple times).

My Personal Notes arrow_drop_up
Last Updated : 12 Jun, 2020
Like Article
Save Article
Similar Reads