Based on the memory hierarchy we use multiple memory components in our computer systems. These memory components have different characteristics with their respective advantages and disadvantages. Efficiently managing data across them helps us create cheaper memory solutions without sacrificing speed and capacity. Based on their characteristics and the use case in the computer, system memory is categorized into different groups.
Volatile and non-volatile memory
Computer memory is primarily of two types based on its ability to store data either permanently or temporarily. Permanent memory solutions like disk drives that are used to store data even when the computer is turned off are called non-volatile memory. They function even when power isn't supplied to the storage device. Temporary memory solutions like the computer's RAM that can only store data as long as power is supplied are called volatile memory.
Volatile memory and non-volatile memory are used for completely different purposes in the computer system and each works to fulfill a particular role.
Registers
Registers are a part of the computer CPU and are directly used to store data in the form of bits. For example, an instruction, a memory address, characters for input and output, etc. They are the fastest memory in a computer system however they are only able to store a very small amount of data. They typically range from 1 bit to 512 bits in size. Due to their nature and the need for efficiency, registers are of multiple types, each designated for a particular task and working in coordination with others.
A few common types of registers are:
- Address Registers: holds addresses (a reference to a memory location).
- Data Registers: holds data in the form of bits for integers, characters, an array of bits, etc.
- Condition Code Registers: holds truth value; a boolean.
- Instruction Registers: holds the instructions that are being executed by the processor.
RAM
Random Access Memory in a computer is a volatile memory that acts as a bridge between the computer storage or permanent memory and the processor. RAM is specifically termed as 'Random Access' because of its ability to access a particular memory address at any time in contrast to non-volatile memory like a hard disk where data is stored sequentially.
There are two types of RAM; static and dynamic. Most Static RAM or S-RAM use six transistors whereas Dynamic RAM or D-RAM use one transistor and one capacitor to store a bit of data. The naming scheme for static and dynamic stems from the components they use. Transistors used in S-RAM require a constant and static current, but D-RAM uses capacitors to store data that require constant refreshing of power to keep data intact. This is because capacitors steadily discharge/lose the energy stored in them.
Static RAM uses a large number of transistors to store a bit of data compared to Dynamic RAM. This means that Dynamic RAM is much denser (able to store more data in less space), can hold more data, and is cheaper to produce. The drawback is that D-RAM is slower and consumes more energy because it needs to refresh power frequently.
Cache
Cache memory is a bridge between the processor's registers and the computer's main memory which is used to store frequently used data in the computer's main memory. Compared to registers, the cache is larger and slower, however, it is still a very fast memory component in the computer which is inserted between the CPU and the main memory. Cache memory is much quicker than the main memory, which is necessary to utilize the full potential of modern CPUs. Computer cache uses S-RAM which is faster but more expensive and less dense compared to D-RAM. Hence, it resides higher in the hierarchy. Frequently used data in the main memory is copied to the cache memory. This allows the CPU to access that data much faster and not decrease processing time significantly. Cache resides within the computer's CPU.
Cache memory is divided into multiple levels. Most processors have L1, L2, and L3. These levels of cache memory are divided based on the idea of memory hierarchy where L1 is the smallest and fastest among the bunch and the others become slower and larger as they go higher. L1 cache is specifically owned by a single core. L2 cache is shared between two cores and L3 is shared between multiple cores at once.
Main memory
Commonly referred to as primary memory or internal memory, it is where the currently used data is stored. If you are running a program; for example, a browser at the current moment, its data is stored in the computer's main memory right now.
Main memory is a limited resource like any other type of computer memory, so the operating system controls what should be in it at each moment, where it should be located, and when it should be removed. D-RAM is used for this memory which allows the main memory to be of larger capacity while being cost-effective compared to the cache memory.
Secondary memory
Secondary memory is a non-volatile memory that can store data permanently i.e when power isn't supplied. They are also referred to as secondary storage. The CPU however is not able to directly access memory from secondary storage and so necessary data must be copied to the main memory first. Computer programs and users have the ability to specifically manipulate data inside the computer's storage.
Secondary memory uses various technologies; magnetic drives like hard disks, optical disks like CDs and DVDs, mechanical drives like analog phonograph records, and electronic drives like Solid State Drives. Different technologies have different storage capabilities, speeds, and costs per byte. These memory storage solutions are built into the computer itself or are portable allowing for easy transport and use across multiple devices.
Conclusion
In this topic, we explored the various components of computer memory. In summary:
- Volatile memory and non-volatile memory refer to memory components that can store data either temporarily or permanently respectively.
- RAM is of two types; S-RAM and D-RAM.
- Registers are the smallest and fastest types of memory placed inside the processor which stores bits of data.
- Cache memory is a bridge between the processor's registers and the computer's main memory which is used to store frequently used data in the computer's main memory.
- Data that is in use at a particular time is stored in the computer's main memory.
- Secondary storage is a non-volatile memory solution that is used to store data permanently.