-1

I'm trying to figure out which locality (spatial/temporal) is used in the following pseudo code and how?

for i = 0, i < 10, i++ 
    sum = sum + array[i] 

I hope my question is clear and somebody could help me, thanks in advance! Steven

Steven
  • 1,123
  • 5
  • 14
  • 31
  • 1
    possible duplicate of [Spatial vs. Temporal locality](http://stackoverflow.com/questions/7264767/spatial-vs-temporal-locality) – Ankur Jan 01 '15 at 17:38
  • sorry, my bad, but could you explain me if the code is making use of temporal locality? assuming "sum" is used 10 times? – Steven Jan 01 '15 at 17:43

1 Answers1

1

Generally, given the code-snippet, one can't just determine easily about spatial locality unless the whole code is given.

Temporal Locality refers to the reuse of specific data, and/or resources, within a relatively small time duration..

Whereas, Spatial Locality refers to the use of data elements within relatively close storage locations.

Next, considering this snippet, as sum is to be called 10 times in 10 iterations of i, hence, repetitive reference to sum depicts temporal locality.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73