Skip to content
Lesson 9

Storage And Memory

If a computer could only run one moment at a time, it would be useless. The reason it can do anything interesting is that it remembers. It remembers what you typed two seconds ago, what you saved last month, what your b…

There is more than one way to understand this. If you have only been taught one, you have been taught less than you deserve.

There is more than one way to understand this. If you have only been taught one, you have been taught less than you deserve.

If a computer could only run one moment at a time, it would be useless. The reason it can do anything interesting is that it remembers. It remembers what you typed two seconds ago, what you saved last month, what your bank balance was at the start of Ramazan. Every program leans on memory the way a cricket scoreboard leans on the runs already scored. The current ball makes sense only because of the runs in the column above it. Take that column away and the next ball is meaningless.

Start with your amma's diary, the one she keeps in the steel almari. Every time someone in the family lends money to a relative, she writes the date, the name, and the amount. Every time the money comes back, she draws a small line through the entry. The diary is a memory. Without it, six months later, no one would remember whether Asif Mamu had returned the fifteen thousand he borrowed for his daughter's jahez. Even good people forget. The diary does not. The reason it works is that it is written down, in one place, in the same order things actually happened. That is the simplest model of computer storage.

Now contrast that with a different kind of memory, the one inside the head of a hafiz e Quran. By the time a child has finished hifz, she carries one hundred and fourteen surahs, six thousand two hundred and thirty six ayat, and the rules of tajweed in her mind. She did not memorise this in one go. The discipline is cumulative. Today she learns one new sabaq. Tomorrow she revises yesterday's sabaq plus the new one. The week's amukhtah is reviewed every Thursday. The month's manzil every month. The whole Quran every Ramazan. Each layer protects the layers below from being forgotten. A computer's storage works the same way, with cache for the most recent, RAM for the working day, and disk for the long term. The hifz student is, without realising it, running the most advanced caching algorithm in the country.

A third example, the family WhatsApp group. Three months ago, your khala pinned a message at the top with the date and the home address of the cousin getting married in Sialkot. The group has had two thousand messages since then, mostly forwards and good morning bouquets. But the pinned message stays at the top. Anyone who joins the group, anyone who scrolls back from the noise, can find it in three seconds. WhatsApp gave the group two storage tiers. The river of normal messages, scrolling, mostly forgotten by the next week. And the small pinned shelf, where the things that must not be lost get nailed down. Almost every database in the world is a more sophisticated version of this same idea.

Storage costs something. Always. Amma's diary takes a page. WhatsApp's pinned message takes a slot at the top of the screen. A program's memory takes space in the chip and slows the computer if it grows too large. The discipline of a good engineer, like the discipline of a good ammi running a tight household, is to know what is worth storing and what is worth letting go. The mehndi function video from your cousin's wedding, save it. The forty seven WhatsApp forwards your phupho sent on Eid morning, let them go. A phone full of forwards is, in computer terms, a cache that has not been cleared. It will eventually run slow, then refuse to take new pictures, and you will be confused why a brand new phone feels old.

Closing thought. Pakistan is a country that remembers. We carry the dates of partition, the words of Iqbal, the score of the 1992 final, the route from your grandmother's pind to your house. Memory is not a foreign idea here. The leap to programming is small. You already know that some things are worth writing in the steel almari, some are worth pinning to the top of the group, and some are worth letting flow down the river. Code is just the practice of doing this with new objects, in new tools, on a faster surface than paper. The instinct to pick what stays is yours already.

Estimated time: 13 min