What is locality of reference?

前端 未结 4 1012
栀梦
栀梦 2020-12-12 16:28

I am having problem in understanding locality of reference. Can anyone please help me out in understanding what it means and what is,

  • Spatial Locality of refer
4条回答
  •  自闭症患者
    2020-12-12 17:11

    Temporal locality of reference - A memory location that has been used recently is more likely to be accessed again. For e.g., Variables in a loop. Same set of variables (symbolic name for a memory locations) being used for some i number of iterations of a loop.

    Spatial locality of reference - A memory location that is close to the currently accessed memory location is more likely to be accessed. For e.g., if you declare int a,b; float c,d; the compiler is likely to assign them consecutive memory locations. So if a is being used then it is very likely that b, c or d will be used in near future. This is one way how cachelines of 32 or 64 bytes, help. They are not of size 4 or 8 bytes (typical size of int,float, long and double variables).

提交回复
热议问题