📖

Worked Example: How Memory Works

Follow along step-by-step as we explore how different types of memory work together.

Example: A Day in the Life of Computer Memory

Let's follow what happens to memory from when you turn on your computer to when you shut it down.

1

Pressing the Power Button

ROM

BIOS Instructions
Hardware Test Code
Boot Sequence
Always has data
→

RAM

(Empty)
(Empty)
(Empty)
Was off - empty

What's happening:

  • RAM is empty because it's volatile - it lost all data when power was off
  • ROM still contains the BIOS because it's non-volatile
  • CPU reads boot instructions from ROM
  • BIOS performs POST (Power On Self Test) to check hardware
2

Loading the Operating System

Hard Drive (Secondary)

Windows OS Files
Your Documents
Programs
Permanent storage
→ COPY →

RAM

Windows Kernel
System Services
Desktop Manager
Loading OS...

What's happening:

  • BIOS finds Windows on the hard drive
  • Essential OS files are copied from hard drive to RAM
  • Original files stay on hard drive (it's a copy, not a move)
  • CPU can now execute the OS from fast RAM
Why copy to RAM? The CPU cannot execute programs directly from the hard drive - it's too slow. RAM is much faster, allowing smooth operation.
3

Opening Microsoft Word

RAM (8GB Total)

Windows (2GB)
Word (1GB)
Free (3.2GB)

What's happening:

  • Word program files copied from hard drive to RAM
  • Word's interface, menus, and features loaded
  • RAM now holds: OS (2GB) + Word (1GB) = 3GB used
  • Still 5GB free for other programs and data
4

Typing a Document (Cache in Action)

CPU

L1 Cache (64KB) - Current letter
L2 Cache (512KB) - Recent words
L3 Cache (8MB) - Current paragraph
↑↓

RAM

Full document

What's happening:

  • As you type, the CPU predicts what data you'll need next
  • L1 Cache: Stores the exact character being processed
  • L2 Cache: Stores recent words and formatting
  • L3 Cache: Stores the current paragraph/section
  • Most data found in cache = cache hit = very fast!
Speed Comparison:
L1 Cache
~1 nanosecond
RAM
~100 nanoseconds
SSD
~100,000 nanoseconds
5

Opening Too Many Programs (Virtual Memory)

RAM (8GB) - FULL!

Windows
Word
Chrome
Game
↔ SWAP ↔

Virtual Memory (Page File)

Chrome Tab 5 (swapped)
Chrome Tab 12 (swapped)
Game textures (swapped)
On Hard Drive - SLOW!

What's happening:

  1. RAM is completely full (8GB used)
  2. OS identifies least-recently-used data
  3. This data is moved to the "page file" on hard drive
  4. RAM space is freed for active programs
  5. If swapped data is needed, it's loaded back (causing delay)
Warning: Virtual memory is 1000x slower than RAM! If this happens too often, you'll experience lag and the dreaded "disk thrashing".
6

Saving Your Document

RAM

Your Essay (unsaved)
Temporary!
→ SAVE →

Hard Drive

essay.docx (saved)
Permanent!

What's happening:

  • While working, your document only exists in RAM
  • When you press Save (Ctrl+S), it's copied to the hard drive
  • Now it exists in BOTH places (RAM for working, hard drive for storage)
  • If power fails, the hard drive copy survives!
Top Tip: Save often! Until you save, your work only exists in volatile RAM.
7

Shutting Down

RAM (After Shutdown)

(All data lost)
(All data lost)
(All data lost)
Power off = empty

ROM (After Shutdown)

BIOS Instructions
Hardware Test Code
Boot Sequence
Still has data!

Hard Drive (After Shutdown)

Windows OS
essay.docx
All your files
Still has data!

What happens to each type of memory:

Memory Type After Shutdown Why?
RAM All data LOST Volatile - needs power
Cache All data LOST Also volatile
ROM Data KEPT Non-volatile
Hard Drive Data KEPT Non-volatile

Key Takeaways

🧠

RAM is Working Memory

Fast but temporary. Stores currently running programs and open files.

🔒

ROM is Boot Memory

Permanent but small. Contains BIOS to start up the computer.

🚀

Cache Speeds Things Up

Tiny but ultra-fast. Stores frequently accessed data near the CPU.

🔄

Virtual Memory is a Safety Net

Uses hard drive when RAM is full. Prevents crashes but causes slowdowns.

← Previous: Predict Next: Trace Memory →