seegongsik
Saved words
Structure

Fast memory and big memory

For the CPU to calculate, values must be close by. But fast memory is small, and big memory is slow. So a computer splits memory into layers. Like a nearby desk and a far-off bookshelf.

01

The desktop and the bookshelf

Think of studying.
On the desk within reach
you can keep only a few books,
but you grab them at once.
A shelf holds many,
but you have to get up and go.
Memory is the same.
Close means fast and small,
far means big and slow.

Speed
Fast
Size
Small
The desk grabs fast, but holds little.

The trade between near and far.

You can't have both.
Memory that's fast and big too
is too expensive
or hard to make.
So you have to choose.
A little, but fast,
or a lot, but slow.

02

Stack them by closeness

So a computer
doesn't keep one kind of memory.
From the tiny, fast memory
closest to the CPU,
to far, big, slow memory,
it stacks them in layers.
Higher up, faster and smaller,
lower down, bigger and slower.

Register
The fastest and smallest memory, right inside the CPU.

Top fast and small, bottom big and slow.

The memory we saw in lesson 9
is one of these layers.
Above it are the faster
cache and registers,
below is the bigger, slower
storage.
Put what you use often up high,
what you use rarely down low.

03

Grab from the desk, or go to the shelf

When the CPU
needs one value,
if it's in the nearby cache
it grabs it in a blink.
If it has to go far to memory,
it takes that much longer.
Even the same value,
by where it is,
splits the time.

From cache (near)Fast
From memory (far)Slow
Fetching from the nearby cache is much faster. So often-used values go in the cache.

Near vs far, the time to fetch.

So a computer
moves a value it just used,
or will likely use soon,
into the nearby cache.
So next time it's needed
it doesn't go far.
A small preparation
saves a lot of time.

04

Is it on the desk, or not

If the value the CPU looks for
is already in the nearby cache,
it's a "hit."
It grabs it right away.
If not, a "miss."
It has to go all the way to memory.
So keeping what's used often
in the cache matters.

The CPU looks for a value
Checks the cache
It's there!
Hit · grab it right away
In cache means hit (fast), not means miss (goes to memory and back, slow).

By whether the value is in the cache.

The more hits,
the faster the computer.
So the rule "keep what you'll use often
close by"
is the heart of handling memory.
Using a small cache
cleverly.

05

Can't it all be fast?

"Can't we just fill it
all with fast memory?"
Then it's too expensive,
and can't hold much.
"All with big memory?"
Then it's too slow.
The layers are
a compromise between the two.
Choose and see why.

Speed
Size
Cost
Catches speed and size, and the cost fits
Layers are the answer because they catch both speed and size to a degree, while the cost fits too.

All fast · all big · layers.

What you use often, in the small fast top layer,
what you use rarely, in the big slow bottom.
Thanks to this clever split
a computer is fast
yet remembers a lot.
Next time we'll see
how all these parts
connect into one machine.

In one lineFast memory is small and costly, big memory is slow. So a computer stacks memory in layers, by closeness. Putting often-used values in the nearby cache raises hits and makes it faster. A small preparation saves a lot of time.
Was this helpful? Support seegongsik
Structure