← ⚡ Cache Memory
Subtopic 2 of 9

3.2Direct mapped

The idea

In a direct-mapped cache each memory block has exactly one place it can go: line = block mod number of lines.

Think of it like this: Car parking where your space number is your ticket number mod 4. Cheap and fast, but two cars with 0 and 4 fight over space 0.

Why it exists

Checking one fixed line is the simplest and fastest hardware: one comparator.

How it works

  1. Compute the line number from the block number.
  2. Compare the stored tag with the block's tag.
  3. Match: hit. No match: miss, and the old block is replaced.
  4. Blocks with the same line number cause conflict misses.

Worked example: 4 lines

Blocks 0, 4, 8 and 12 all map to line 0 (b mod 4 = 0). Accessing 0, 4, 0, 4 misses every time even though 3 lines are empty.

Now play with it

  • →On the Direct tab click blocks 0, 4, 0, 4 and watch line 0 thrash.
  • →Hover a block to see the one allowed line.

Main memory blocks (click one to access it)

Cache lines (4)

line 0·
line 1·
line 2·
line 3·

Click memory blocks below. Try 0, 4, 0, 4 in direct mapped.

Hover a block to see which lines it is allowed to use. Block b → line b mod 4.

Check yourself

Direct-mapped cache with 8 lines. Memory block 19 goes to which line?

Remember: One home per block: simple, but conflict-prone.
Exam notes (the dense version)

Block j → line (j mod #lines). 1 comparator, cheap, fast, but conflict misses.

Previous year questions: Cache Memory (22)

PYQs are grouped by topic, so this is the full set for Cache Memory; try the ones that match this subtopic. Open all 22 on the topic page.