Types of Memory
Types of memory in increasing order of location from CPU

Types of Memory

At a high level, there are four types of memory in a computer — primary, secondary, cache, and registers. Following are some examples for each of the memory types:

Primary: RAM, ROM Secondary: Harddisk, Pen drive, Floppy Disk, CD Cache: L1, L2,L3 caches Registers: Accumulator(AC), Memory Address Register(MAR), Memory Data Register(MDR), Program Counter(PC) etc.

Now, let’s take a look at each of the memory types and try to understand the core differences among all of them.

1) Primary vs 2)Secondary

Let’s take a look at some points for comparing primary and secondary memory!

  1. Definition: Primary memory also known as the computer’s main memory is mainly accessible by the CPU for faster execution of programs whereas secondary memory is used for permanent storage.
  2. Speed: The programs or instructions are loaded into the primary memory because accessing the programs from primary memory(like RAM) is much faster than the secondary.
  3. Volatile: Primary memory is volatile in nature that is if the power failure occurs, all the changes made will be lost and will not be available upon rebooting your computer. The secondary memory is non-volatile in nature (for example: disk) which persists all the changes even in cases of power failures.
  4. Cost: Primary memory is costlier in comparison to secondary memory.
  5. Memory: Primary memory is limited/smaller in comparison to the Secondary memory. For example: RAM(type of primary memory) in our computers might only be 8GB whereas Hard disks(type of secondary memory) in our computers might be up to 1TB.

But wait, how are Primary and secondary memory types related to program execution? Imagine this: When you open any application on your computer, the processor in your computer brings all the data related to your application from the secondary memory into the primary memory and then the processor executes instructions performed by the user.

Is the CPU a Processor? Quoting here from Techopedia: Most people use the word “processor” interchangeably with the term “CPU” nowadays, it is technically not correct since the CPU is just one of the processors inside a personal computer (PC). The Graphics Processing Unit (GPU) is another processor, and even some hard drives are technically capable of performing some processing. To sum it up, yes, your CPU is a processor!

Types of Primary

As discussed earlier, there are two types of Primary memory:

1) Random Access Memory (RAM)

RAM is one of the computer's main memory that allows faster read and writes. Since it’s a kind of primary memory, it’s volatile in nature which means changes made will be lost once the computer is switched off or in case of power failure.

Example of RAM, Credits: Javatpoint

2) Read Only Memory (ROM)

As per Wikipedia, “Read-only memory is a type of non-volatile memory used in computers and other electronic devices. Data stored in ROM cannot be electronically modified after the manufacture of the memory device. Read-only memory is useful for storing software that is rarely changed during the life of the system, also known as firmware.”

Example image of ROM, Credits: Javatpoint
Why ROM is a non-volatile memory though it’s a type of primary memory? The crux of the issue lies in the definition of "primary memory." While it's true that ROM is non-volatile, it's also very fast and directly accessible by the CPU, making it functionally similar to RAM in terms of its role in the system.
Due to it’s functional similarity with RAM, ROM is often considered a type of fast, non-volatile primary memory. It typically stores essential system files, like the BIOS (Basic Input/Output System) and firmware, which are crucial for booting up and running the computer. These files need to be readily available for the CPU to access but don't necessarily need to be constantly modified.

Types of Secondary

Hard disk, USB Pen Drive, Floppy Disk, CD etc are all examples of Secondary storages. These storages persist data in them permanently and don’t cause loss in data even in case of power failures. You might have used Pen drive and CD’s extensively if you were born in 90’s ;)

3) Cache

Cache memory is a small chip based computer memory that lies between the CPU and the main memory. It is fast and a temporary memory solution to enhance the performance of the CPU. Because of the cache’s proximity to the CPU, this is also called as CPU memory.

CPU cache(L1,L2,L3), Credits: EventHelix

Here are the different types of caches:

  1. L1 cache: - fastest memory for accessing the data among L1, L2, L3 caches - as a hardware, it's placed closest to the CPU cores - measured in KiloBytes or usually max goes up to 1MB - approx 100x faster than your system RAM - L1 cache internally consists of two parts: [1] Data cache: holds the data on which the operation is to be performed [2] Instruction Cache: deals with the information about the operation that the CPU must perform
  2. L2 cache: - slower in terms of data access but bigger in size than the L1 cache - also fitted inside each individual CPU core - usually measured in single-digit MBs - approx 25x faster than your system RAM
  3. L3 cache: - larger in size than L1 and L2 caches - placed outside of the CPU core and shared across multiple CPU cores - It's a generic memory pool that the entire chip can use

The L1, L2 and L3 caches are faster memory access option compared to the main memory. Cache memory stores all data and instructions that are repeatedly used by the CPU for improving the performance of a computer. Moreover, caches are must costlier compared to the primary memory and secondary memory.

4) Registers

Registers are type of computer memory that are built directly into the CPU that is used for storing and transferring the data and instructions to the computer. It is the smallest and fastest memory of a computer. The register memory is 16, 32 and 64 bits in size.

There are different types of registers available and thus may store different type of data such as an instruction, a storage address, or any kind of data for that matter depending upon their type.

Here are some examples of registers with their respective applications in brief:

  1. Accumulator (AC): Stores the results of arithmetic and logical operations.
  2. Memory Address Register (MAR): Holds the memory address of the data to be accessed.
  3. Memory Data Register (MDR) : Stores the data being read from or written to the memory. MAR and MDR together facilitate the communication of the CPU with the main memory.
  4. Program Counter: Points to the next instruction to be executed.
  5. Instruction Register: Holds the current instruction to be executed.
  6. Condition code registers: contains different flags that indicate the status of any operation.

… etc (there are many more kinds of registers)

Conclusion

To enhance execution speed, a computer's CPU relies on accessing data from memory. Registers, which are shorter in size, conveniently fit into the CPU due to their compact nature. On the other hand, larger memory types, such as hard disks, occupy more space and are situated farther away from the CPU. Consequently, the proximity of registers facilitates faster instruction execution, while the distance and size of disks contribute to slower instruction performance.

Thus, increase in size causes the memory type to be further away from CPU and thus causing slower reads/writes.


That’s it, folks for this edition of the newsletter. I hope this edition of newsletter with the help of images helped you visualize how different types of memory in our computer look like. Please consider liking and sharing with your friends as it motivates me to bring you good content for free.

Resources

Classification of memory - Javatpoint

Cache memory - TechTarget

Different types of Registers - GFG

Register by TechTarget

Shrutkirti Gupta

Senior Software Engineer at Uber | Ex- Morgan Stanley | Ex- Barclays

1 年

Well articulated. Thanks for sharing!

Prakash Kumar

Student at Sant Longowal Institute of Engineering & Technology

1 年

I give you all answers... please connect me.

Anchal Sharma

Engineering @Myntra (Flipkart) || Ex-PayPal || 120K+ @LinkedIn || Mentor

1 年

Insightful ??

Kartik Kaushik

Full Stack developer | content creator| open for collabs

1 年

Nice one article u have written Vivek Bansal

要查看或添加评论,请登录

Vivek Bansal的更多文章

  • How to implement a Circuit Breaker

    How to implement a Circuit Breaker

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    7 条评论
  • How to implement Consistent Hashing

    How to implement Consistent Hashing

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    3 条评论
  • Optimistic Locking Implementation

    Optimistic Locking Implementation

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

  • 1 year to Curious Engineer ??

    1 year to Curious Engineer ??

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

  • Message Queues vs Message Brokers

    Message Queues vs Message Brokers

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    4 条评论
  • Introduction to gRPC

    Introduction to gRPC

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    7 条评论
  • Non-Functional Requirements

    Non-Functional Requirements

    Brief Introduction Let’s say you are building a website that allows users to book flight tickets. The requirements for…

    4 条评论
  • QuadTrees

    QuadTrees

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    2 条评论
  • Text Based Search: ElasticSearch

    Text Based Search: ElasticSearch

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    3 条评论
  • Sharding vs Partitioning

    Sharding vs Partitioning

    If you like the free content I put out, consider subscribing to my newsletter on substack to get a well-researched…

    5 条评论

社区洞察

其他会员也浏览了