Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

What do you mean by locality of reference ? Explain with suitable example.

Locality of reference refers to the tendency of computer programs to access the same or nearby memory locations repeatedly over a short period of time. This principle is based on the observation that when a program accesses a particular memory location, it is likely to access nearby locations in the near future.

There are two main types of locality of reference:

  1. Spatial Locality: This refers to the tendency of a program to access memory locations that are close to each other. For example, when a program accesses a particular memory address, it often accesses nearby addresses as well.
  2. Temporal Locality: This refers to the tendency of a program to access the same memory locations repeatedly over a short period of time. For example, if a program reads a value from a memory location, it is likely to read the same value again in the near future.

Example :

  1. Take the example of an operating system. Ideally, we would like an unlimited amount of main memory, instantly accessible.
  2. In practice, we have a limited amount of main memory, and because it is cheaper, a very large amount of secondary memory.
  3. However the trade-off is that secondary memory tends to be several orders of magnitude slower than primary memory.
  4. We can approach the ideal by keeping the more often used data in main memory, and everything else in secondary memory.
  5. Because of the principle of Locality of Reference, we can be sure that most memory references will be to locations already stored in main memory, thereby improving efficiency and providing a flat memory model.
  6. This scheme is used in modern operating systems and is called virtual memory. Virtual memory gives users the appearance of unlimited primary memory by transparently utilizing secondary memory.

Leave a Comment