Memory Hierarchy
Why your computer uses many types of memory instead of just one.
Why a Hierarchy?
Faster memory (like CPU registers) is very expensive and small, while slower memory (like hard disks) is cheap and large. The memory hierarchy balances speed and cost by layering different memory types.
The Levels
From fastest/smallest to slowest/largest: Registers (inside the CPU), Cache (L1, L2, L3), Main Memory (RAM), and Secondary Storage (SSD/HDD). Data frequently used gets promoted to faster levels.
Locality of Reference
Programs tend to access the same data or nearby data repeatedly (locality of reference). Caches exploit this by keeping recently/frequently used data close to the CPU, dramatically speeding up execution.
đ Real-World Use
When your laptop feels slow after opening too many apps, it's often because RAM is full and the OS starts using the much-slower disk as 'virtual memory' â this is memory hierarchy in action, visibly affecting your experience.
đĄ Pro Tip
Remember the order (fastest to slowest) using: 'Rich Cats Rarely Sleep' â Registers, Cache, RAM, Secondary storage â helpful for quick recall in exams.
đ§Ē Quick Self-Test
Check what you just learned â no pressure, just practice.
1. Which memory type is fastest but smallest?
2. What principle do caches rely on?