Memory Hierarchy & Cache
Expert Answer & Key Takeaways
Understanding the pyramid of computer memory: Registers, Cache (L1/L2/L3), Main Memory (RAM/ROM), and Secondary Storage. Includes Cache mapping techniques.
Memory Hierarchy in Computer Architecture
The memory hierarchy is an arrangement of different types of computer memory based on their speed, capacity, and cost. It is usually depicted as a pyramid. The goal of the hierarchy is to provide the user with the highest possible speed (at the top) and the highest possible capacity (at the bottom) at a reasonable cost.
1. The Memory Pyramid
From top (fastest, smallest, most expensive) to bottom (slowest, largest, cheapest):
- Registers: Built directly inside the CPU. They hold data currently being processed. Capacity is usually in Bytes (e.g., 64-bit).
- Cache Memory: Small, extremely fast static RAM (SRAM) placed between the CPU and Main Memory. It holds frequently requested data.
- Main Memory (Primary Memory): This includes RAM (Random Access Memory) and ROM (Read Only Memory). It is directly accessible by the CPU.
- Magnetic Disks / Solid State Drives (Secondary Storage): Non-volatile storage used to store data permanently (e.g., HDD, SSD).
- Optical Disks / Magnetic Tapes (Tertiary Storage): Used for backups and archives (e.g., CDs, DVDs).
2. Main Memory: RAM vs ROM
2.1 RAM (Random Access Memory)
RAM is volatile, meaning it loses its data when the power is turned off. It is the 'working space' of the computer.
- SRAM (Static RAM): Uses flip-flops. Does not need to be refreshed periodically. Very fast, very expensive. Used for Cache Memory.
- DRAM (Dynamic RAM): Uses capacitors and transistors. Must be refreshed constantly (thousands of times per second) otherwise it loses data. Slower but cheaper. Used for standard Main Memory.
2.2 ROM (Read Only Memory)
ROM is non-volatile. Data remains even when power is off. It contains crucial boot instructions like the BIOS.
- PROM: Programmable ROM (can be written to only once).
- EPROM: Erasable Programmable ROM (erased using Ultraviolet light).
- EEPROM: Electrically Erasable Programmable ROM (erased electrically, used in Flash drives).
3. Cache Memory & Principle of Locality
Because RAM is much slower than the CPU, waiting for data from RAM creates a bottleneck. Cache Memory acts as a high-speed buffer. When the CPU needs data, it checks the Cache first (Cache Hit). If it's not there (Cache Miss), it fetches it from RAM.
Cache works based on the Principle of Locality:
- Spatial Locality: If a memory location is accessed, it is highly likely that nearby memory locations will be accessed soon (like reading an Array).
- Temporal Locality: If a memory location is accessed, it is highly likely it will be accessed again very soon (like a variable inside a Loop).
Cache Mapping Techniques
How do we map large Main Memory blocks into the much smaller Cache?
- Direct Mapping: Each block of main memory maps to exactly ONE specific cache line. (Fast, but high chance of collision).
- Associative Mapping: A main memory block can be loaded into ANY line of the cache. (No collisions, but slow to search).
- Set-Associative Mapping: A compromise. The cache is divided into 'sets'. A memory block can map to ANY line within a specific set.
Course4All Editorial Board
Verified ExpertSubject Matter Experts
Comprising experienced educators and curriculum specialists dedicated to providing accurate, exam-aligned preparation material.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.