I have read about spatial and temporal localities.
In a couple of words.
Temporal locality: Programs often access the same memory locations repeatedly.
Spatial locality: Programs also often access adjacent memory locations repeatedly.
Now I'm tying to analyse the following code to find all the occurrences of temporal and spatial locality of reference.
for (int i = 0, j = 10; i < 100; i++)
a[i] = j++;
I figured out only the followings.
Spatial
a[i] = j++;
After referencinga[i]
we are about to referencea[i+1]
.- The instructions to do all this are stored in next to each other in memory.
Temporal
i
compared against 100.i
incremented by the one:i++
.- The assignment
a[i] = j++
usesi
as array index. - Array base
a
used for indexing eacha[i]
. j
incremented by the one in assignmenta[i] = j++
.
So am I correct in all of these and did I miss something else?