CS core subjects

Stage 1 · Lesson 5 of 7

The memory hierarchy and caches

How a computer runs a program

A computer keeps data in several places, and they differ in speed by orders of magnitude. From fastest to slowest: registers, CPU (small, fast memory next to the processor), , SSDs and storage on the network. Reading a register takes under a .

Main memory takes around a hundred nanoseconds. A disk or network call can take milliseconds. This ladder is the memory hierarchy.

Caches work because programs tend to reuse data they used recently, called temporal locality. They also tend to read addresses next to each other, called spatial locality. That is why looping over an array in order is faster than jumping around a , whose items can sit anywhere in memory. The same idea returns later in database and web caches.

Common trapjudging performance only by counting operations and ignoring where the data lives.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

Keep handy

  • A topic map of the whole CS curriculum to check your coverage against, stage by stage

  • Short explanations from researchers when one idea, such as floating point, will not click

Also worth your time

Mark this stage as not done?