How do computers “store” memory? Why isnt data lost the power is cut?

142 views

How do computers “store” memory? Why isnt data lost the power is cut?

In: 3

5 Answers

Anonymous 0 Comments

Oh boy, this is where I shine!

Let’s say you have 3 light switches in your room. If you flip two off, and keep one on, then you had an electric outage. When the electricity comes back on, will the light switches change position?

No. They will remain exactly where you left them. The ones that you left off will remain off, and the one that you flipped on is still flipped on.

In very simple terms, a computer is essentially made up of a bunch of very tiny light switches.

A computer is made up of many components, the most notable analogy for this question is ROM. ROM is the most basic permanent storage.

ROM (Read Only Memory) is made up of transistors. A transistor is an electric component that can be either ON or OFF. In other words, it is a tiny light switch.

Thanks to a bunch of geniuses who came up with this stuff with no access to stackoverflow or the internet, our alphabet and numbers can be represented in bits. What is a bit, you ask? Let’s say you have 2 transistors in the row as follows:

[0] [0]

Each of these transistors is either on or off. In this case, they’re both off: hence, the 0 values. In other words, the value these transistors are holding is 00. Let’s call the values in these transistors bits. Since there are two transistors, we have 2 bits.

Anyway, ROM is made up of a whole bunch of these transistors. Let’s say your ROM has 6 transistors. That allows us to store up to 6 bits worth of data. If you want your ROM to remember the number 42 (assuming we’re dealing with binary), we save this number as 101010. This is the binary representation of the number 42.

In other words, we switch the first transistor on the left ON, we keep the next one OFF, we switch the one after that ON, the next one OFF, so on and so forth until we have:

ON OFF ON OFF ON OFF. Or, if we were to represent 1 as ON and 0 as OFF, then in other words, 101010.

Now, those transistors (light switches) are, for lack of a better word, permanently in that state. It doesn’t matter if you kill the power, or not, just like it didn’t matter with your room’s light switches. They are literally physically set.

At a very high level, that is how your computer is able to keep your data in spite of loss of power.

Bonus: However, a modern computer doesn’t exactly work like that because that’s not a very efficient use of space. There is one single component in a modern PC for which this does not apply: RAM (Random Access Memory). All the transistors in a RAM will wipe their data (ie all return to 0) once their power is cut off. They’re engineered that way because your computer constantly needs to store temporary information and wipe it while you’re using it. Of course, this is an oversimplification, since we’re actually dealing with memory addresses and on a much bigger scale and with a very advanced rate of virtualization of memory thanks to modern technology. But at core, that is how it works.

It’s also slightly different for a magnetic drive (HDD), but the idea remains the same of storing data as either 0 or 1. Basically, all you need is a way to represent data in a bi-state of sorts, whether it be stroking paint vertically for 0 or horizontally for 1, or turning a light switch off for 0 or on for 1, or even drawing a circle for 0 and a square for 1. All you need is a way to store which transistors should turn ON and which transistors should turn OFF to represent this data. But that is also what makes HDDs susceptible to corruption with a simple magnet – because it stores this data by magnetized strokes.

Which takes me to my next point:

Let’s say you wrote down instructions on which light switch you kept on and which light switch you kept off, on a piece of paper. Even if someone were to play around with the lights later, if you wanted to set your light to exactly how you had it when you wrote it down, all you have to do is look at the piece of paper you wrote to find out which light switch to turn on and which to turn off.

A computer doesn’t actually need to keep the transistors (light switches) in exactly the same positions you left them. All it needs is to store those positions somewhere, so that when you try to retrieve it, it can put everything back exactly how you need it to be. This is where hard drives come in.

Keeping 1 terrabyte worth of transistors in your computer at one point was very costly, and would’ve taken up a fair amount of space. So engineers came up with more clever ways to store data as magnetic films (floppy disks), magnetic drives (HDDs), etc… Nowadays, its relatively cheap to have transistors, so we have what we call SSDs which utilize flash memory.

Hard drives contain instructions about which transistors the computer needs to flip on and off. At this level of detail, a computer is what we call a “processor.” That’s that thing that’s labeled Intel or AMD. This is the thing that does all the work, goes to fetch all the instructions from the hard drive, does all the calculations, and sends it to its friends to display, mainly RAM and GPU. So when you click on a picture that you saved on your computer, your processor goes to your hard drive like “Hey, what’s the instructions for this picture?” Your hard drive then goes “oh I know exactly where this is! Let me get it for you.” In the case of older HDDs, it would do a spinny-wirl thingy to get to the sector where the data is stored, then gives the instructions to the CPU. The CPU then does whatever computations it needs to do, and sends orders to the RAM and GPU like “I need you to do these things and flip these switches.” And you have your picture.

This happens constantly, from the second you use your computer. Your processor goes to your hard drive to ask for instructions on where your desktop icons are and what your wallpaper is, your hard drive gives over the instructions, your processor flips whatever transistors it needs to flip, does its calculations, and sends some instructions over to RAM and GPU. It happens hundreds, thousands, of times a second, all the time. And it does it with such a high degree of efficiency and complete accuracy. It’s mindblowing if you think about it.

You are viewing 1 out of 5 answers, click here to view all answers.