Memory
Summary
A computer keeps bits in two kinds of places. While it runs, they live in main memory, millions of tiny circuits that each hold one bit for as long as the power is on. When it is switched off, they live on a disk or in flash memory, as a physical state that stays put by itself: a magnetised spot, a trapped charge. Storing always means setting such a state; reading means asking for it. Between the two, a file travels as what it is, the same sequence of bytes.
The questions
- How can a circuit built from gates remember a bit?
- Why does main memory forget when the power goes off, and a disk does not?
- What does an address do, and why does every byte need one?
- How do a magnetised spot and a trapped charge hold a bit without power?
You meet this concept in Challenge 4, where a whole file has to be held on one computer, sent, and held again on the other.
The concept explained
A bit that remembers
In Logic and Arithmetic you saw that two NOR gates wired into each other make a flip-flop: a short pulse on set makes the output 1, and the cross-wiring keeps it there until reset. That is one bit of memory, built from the same switches that add and compare. Eight flip-flops side by side hold a byte; that is a register, the small fast memory inside the processor. Nothing about the circuit knows whether the byte is a number, a letter or a pixel, it just holds eight states.
Main memory: millions of them, each with an address
Main memory, the RAM of your laptop, is billions of such cells arranged in rows. Every row has a number, its address. To read a byte, the processor puts the address on a set of wires, the address lines, and the row answers on another set, the data lines; to write, it does the same the other way round. That is why a program never says “the number over there”: it says “the byte at address 4711”. The address is the only handle the machine has.
All of this holds only while the power is on. The flip-flop keeps its bit because its two gates keep feeding each other; cut the power, and the loop collapses. That is not a defect but the price of speed: RAM answers in nanoseconds because nothing has to move. It is also why an unsaved document is gone after a crash, and why saving means copying the bytes somewhere that does not need power.
Storage: a state that stays put
A hard disk stores a bit as the direction in which a tiny spot on a spinning platter is magnetised; a head flying just above the surface flips it to write and senses it to read. Flash memory, in SSDs and USB sticks, traps a small electric charge inside a transistor that is insulated on all sides; the charge stays for years, and reading means testing whether it is there. Both are slower than RAM, because something physical has to happen, and both keep their state without power, which is the whole point. David Macaulay draws all of them in the chapter “Storing Bits” of his book (see below).
The file in between
Whatever the medium, what is stored is a sequence of bytes. When you open a picture, its bytes are copied from the disk into RAM; when you save, they are copied back. When you send it over your light link, the bytes leave RAM one by one, become symbols, become light, and end up in the other computer’s RAM, from where they are written to its disk. At no point does the picture exist as anything but bytes, and at no point do the bytes care where they are. How a file is built so that a program can make sense of those bytes is the topic of Files.
Slides
Practice questions
Practice questions for this concept will follow with the slides.
Further reading
- David Macaulay: The Way Things Work Now. Houghton Mifflin Harcourt 2016, part 5 “The Digital Domain”, chapter “Storing Bits”. Memory chips, flash, hard disks and barcodes in drawings.
- Charles Petzold: Code. The Hidden Language of Computer Hardware and Software. 2nd edition, Microsoft Press 2022. Builds a flip-flop from gates and a memory from flip-flops, one step at a time.