7 minutes read

As you may know, a computer's functionality depends primarily on being able to store and access data. Just like human beings have memories that are used to recall events in the past, computers also require memory that can be used by the processor to access and work with data. In this topic, we will explore computer memory, its main characteristics, and the memory hierarchy. We will also take a look at the Principle of Locality and learn how memory is managed to efficiently store and process the data.

Computer memory and its characteristics

In simple terms, Computer memory is a storage space for data in the form of bits. A computer without memory is useless as data cannot be accessed and the information processed by the computer's processor can't be stored. Different types of computer memory are used in the same computer. Each type of memory has different characteristics which make it suitable for a particular purpose.

Let's take a look at the main characteristics of computer memory:

Capacity: It is the total amount/volume of data that the memory can store. It is preferable for computer memory to have a larger capacity so that more data can be stored and used at any given time.

Access time: It is the time interval between the read/write request and the availability of the data in computer memory. It is essential to have faster access time so that the processor doesn't have to waste time by having to wait for the requested data or to write information into computer memory.

Cost per bit: Different types of computer memory use different technologies and components. Because of this, some are expensive while others are cheap. Cheap memory solutions allow us to use more memory and help increase affordability. Computers have become a basic necessity in our lives so the cost per bit of computer memory is a very important factor for easier accessibility.

Memory hierarchy

The processing power of a CPU depends on a few important factors, one of which is the fast transfer of data from storage to the processor. However, the storage drive we use in our computer isn't fast enough to keep up with the speed at which a processor processes data. Because of this, the processor has to spend more time waiting to read and write data from and into the memory. This issue could be solved by using only fast storage solutions but this is not possible due to the cost implications. To solve this problem we use both fast and slow memory in a computer system and efficiently store data across all of them based on the Principle of Locality.

Memory hierarchy is the hierarchical division of different types of computer memory based on their speed or access latency. Fast memory is placed closer to the processor whereas slower memory is placed farther and farther away. This hierarchy shows a relative trend between access time, storage capacity, and cost per byte.

computer memory hierarchy

Memory components higher in the hierarchy are placed closer to the processor compared to those placed lower in the hierarchy. This is because placing memory components closer to the processor means the time for data to travel from one place to another is reduced. When considering the fact that modern processors have the ability to compute over a trillion instructions per second; the distance between memory components and the processor is highly relevant.

Principle of Locality

Also referred to as Locality of reference, is the tendency of a processor to access the same portion of the address space at a particular instance of time. A common example is the 90/10 rule which states that a processor approximately spends 90% of its time in 10% of the code. Meaning some code is executed much more often than the other.

Spatial locality: The tendency of referencing memory locations close to the location that was referenced before. An easily understandable example of spatial locality would be arrays. When one item in an array is referenced, it is likely that another one will be referenced in quick succession.

Temporal locality: The tendency of a memory location to be referenced in a short interval of time. Loops in computer programs are a great example of temporal locality as various variables used in that loop are referenced again and again.

This is a predictable behavior in computer systems that can be exploited to create the illusion of faster memory. Using the principle of locality we can predict what data is more likely to be used and subsequently store them in memory that is faster.

How is computer memory managed?

The memory hierarchy helps us create the illusion of fast memory by using a combination of both fast and slow memory components. Based on the principle of locality, proper memory management can be used as a solution to the cost implications of using only fast memory components.

The CPU works directly with the data inside registers since they are the fastest form of memory. Operations are performed on this data or with the help of it. Registers are unable to store all the necessary information at once. The computer stores all necessary data in its main memory, but it is rather slow and unable to keep up with the demands of the CPU. So, the cache acts as a bridge between fast registers and slow main memory. Cache memory is larger and slower than registers but smaller and faster than main memory and is used to store frequently used data.

proper memory management based on the principle of locality

When the CPU works on a process, it looks for the data in the memory component that is at the top of the hierarchy. In case the CPU doesn't find the required data, it looks for data in the components that are lower in the hierarchy. When the required data is found, it is duplicated in the components higher in the hierarchy.

Our CPU first looks whether the data is present within its registers. If not it looks for them in the cache memory. If not found, the CPU will search for the necessary data in the main memory and lastly in the computer's secondary memory if it is not present in the main memory.

We will take a detailed look at memory components like register, cache, main memory, and secondary memory in upcoming topics.

Since there is a lot of back and forth transfer of data between different memory levels, it is very important for memory to be managed properly so as to be efficient. This is done by loading commonly used data and information higher up in the hierarchy, which decreases the average time taken to access data from slower memory.

Conclusion

  • Computer memory is a storage space for all the data in the computer.
  • Computer memory is characterized by its capacity, access time, and cost per bit.
  • The memory hierarchy is a hierarchical division of different types of memory used in a computer, based on the memory's characteristics.
  • Computer data can be efficiently managed across different memory based on spatial and temporal locality.
243 learners liked this piece of theory. 3 didn't like it. What about you?
Report a typo