문제

Hi have some question regarding spatial and temporal locality. I have read in the course theory that

spatial locality

If one item is referenced, the likelihood of other address close by will be referenced soon

temporal locality

One item that is referenced at one point in time it tend to be referenced soon again.

Ok, but how do I see that in the code? I think I understood the concept for temporal locality but I don't understand spatial locality yet. For instance in this loop

for(i = 0; i < 20; i++)
    for(j = 0; j < 10; j++)
        a[i] = a[i]*j;

The inner loop will call same memory address when accessing a[i] ten times so that's an example for temporal locality I guess. But is there spatial locality also in the above loop?

도움이 되었습니까?

해결책

Of course. For instance, after referencing a[5] you are about to reference a[6].

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top