- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the locality of reference?
Locality of reference refers to the tendency of the computer program to access the same set of memory locations for a particular time period. The property of Locality of Reference is mainly shown by loops and subroutine calls in a program.
On an abstract level there are two types of localities which are as follows −
This type of optimization includes bringing in the frequently accessed memory references to a nearby memory location for a short duration of time so that the future accesses are much faster.
For example, if in an instruction set we have a variable declared that is being accessed very frequently we bring in that variable in a memory register which is the nearest in memory hierarchy for faster access.
This type of optimization assumes that if a memory location has been accessed it is highly likely that a nearby/consecutive memory location will be accessed as well and hence we bring in the nearby memory references too in a nearby memory location for faster access.
For example, traversal of a one-dimensional array in any instruction set will benefit from this optimization.
Using these optimizations we can greatly improve upon the efficiency of the programs and can be implemented on hardware level or on software level.
Let us see the locality of reference relationship with cache memory and hit ratio.
Relationship with Cache memory
Cache is a specially designed faster but smaller memory area, generally used to keep recently referenced data and data near recently referenced data, which can lead to potential performance increases.
Data in cache does not necessarily correspond to data that is spatially close in main memory. However, data elements are brought into cache one cache line at a time. This means that spatial locality is again important. If one element is referenced, a few neighbour elements will also be brought into cache.
Finally, temporal locality plays a role on the lowest level, since results that are referenced very closely together can be kept in the machine registers. Programming languages such as C allow the programmer to suggest that certain variables are kept in registers.
Relationship with Hit ratio
Hit ratio is the concept defined for any two adjacent levels of a memory hierarchy. It is the probability that an information item will be found in the memory we are looking at.
So locality of reference needs a good Hit ratio for achieving Fast Access time.
- C++ Program to Perform Searching Based on Locality of Reference
- What is the OSI Reference Model?
- What is the TCP/IP Reference Model?
- What is The Rule of Three with reference to C++?
- What is a reference variable in C++?
- What is the difference between object and reference in java?
- What is ‘this’ reference in Java?
- What is pass by reference in C language?
- What is call by reference in C language?
- What is a reference/ref parameter of an array type in C#?
- What is B-ISDN reference model in computer network?
- What is the difference between pass by value and reference parameters in C#?
- What are Memory Reference Instructions?
- What is a forward reference in JShell in Java 9?
- The OSI Reference Model