Stage 1 · Lesson 5 of 7
The memory hierarchy and caches
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
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
The first weeks in C teach binary, memory, pointers and the stack and heap with excellent problem sets
- VideoFreeCrash Course Computer Science
CrashCourse · Beginner
Short videos from transistors to CPUs and memory; the quickest way to see the whole picture