Types of Memory
Memory and storage can be classified into three groups: primary memory, cache and persistent storage.
Primary Memory: RAM and ROM
Understanding Primary Memory
Primary memory is the only storage directly accessible by the CPU. It holds data and instructions currently in use, stored
Primary memory
The only storage directly accessible by the CPU. It holds data and instructions currently in use, stored as binary machine code.
as binary machine code.
Primary memory has two components:
- Random Access Memory (RAM)
- RAM holds executing program instructions and any necessary data.
- Each piece of data is stored in a unique memory location with an address and content.
- Read-Only Memory (ROM)
- ROM holds instructions and data in unique memory locations, similar to RAM.
- These instructions are critical for booting and basic system operations.
Imagine working on a document. The unsaved changes reside in RAM. If the power goes out, those changes are lost.
ExampleThe BIOS (Basic Input/Output System) is stored in ROM. It initializes hardware components during startup.
NoteROM is often smaller than RAM but plays a crucial role in system stability by providing essential startup instructions.
| Feature | RAM | ROM |
|---|---|---|
| Volatility | Volatile (loses data when power is off) | Non-volatile (retains data without power) |
| Modifiability | Read and write (continuously updated with executing program instructions and data) | Read-only |
| Purpose | Stores executing programs and data | Stores permanent instructions (e.g., BIOS) |
| Size | Typically larger | Smaller |
| Upgradability | Usually upgradeable, can be increased | Usually part of motherboard, difficult to upgrade |
| Use Case | Running applications and temporary data storage | Booting and essential system operations |
Think of RAM as a workspace where you actively work on tasks, while ROM is a reference book with essential instructions that never change.
Common MistakeDon't confuse RAM and ROM. RAM is for temporary, volatile storage, while ROM is for permanent, non-volatile instructions.
Cache
Cache memory
Cache memory is a high-speed memory located close to the CPU, designed to store frequently accessed data and instructions.
Cache memory is typically made of Static RAM (SRAM), which is faster but more expensive than the Dynamic RAM (DRAM) used in main memory.
A cache memory significantly reduces the time it takes for the CPU to access data, as it is much faster than RAM.
Analogy- Think of cache memory as a personal assistant who keeps your most important documents on hand.
- Instead of searching through a filing cabinet (RAM) every time you need something, you can quickly access what you need from your assistant (cache).
Cache works in a few steps:
- Data Request: When the CPU needs data, it first checks the cache.
- Cache Hit: If the data is in the cache, it's retrieved quickly.
- Cache Miss: If the data is not in the cache, it's fetched from RAM and stored in the cache for future use.
Cache can have multiple levels:
- L1 Cache:
- Located on the CPU chip.
- Smallest and fastest.
- Divided into separate caches for instructions and data.
- L2 Cache:
- Larger than L1.
- May be on the CPU or a separate chip.
- L3 Cache:
- Shared among multiple CPU cores.
- Larger and slower than L1 and L2.
- Modern CPUs often have multiple cache levels to balance speed and cost.
- Each level is progressively larger and slower.
- Consider a video editing application.
- The CPU frequently accesses the same set of instructions and data (e.g., rendering algorithms, video frames).
- By storing these in the cache, the application runs more smoothly and efficiently.
In multicore systems, each core may have its own cache.
Cache coherency ensures that all caches have a consistent view of memory: