Laymans answer: How does memory work in a computer?

Hi, I am getting more and more into computers.
One thing I don’t understand is how does memory work.
I am not sure my model is correct, but what I understand is this:

Everything in a computer involves circuits.
Circuits work by electricity.
In order for the computer to function, electricity must flow through the circuits (BUT!) If the way the computer works is pure electricity, then I don’t see how anything would be stored anywhere, because once the electricity goes out of the machine, nothing is happening in it. I am not sure then how you can store memory in it…

So, can someone please show where my map is wrong?

You’re forgetting about the magnets.

Capacitors can store charge which can be used to store a state. That’s a super brief explanation of how it could work with electricity even though it seems like electricity is temporary. Which it is, but it isn’t instantaneously on and off.

How RAM Works | HowStuffWorks

The above link is a bit more in depth.

Indeed. Most memory is “volatile”, meaning that it requires power to retain its content.

Which is why computers have a second capability called “storage”. These are components like disk drives (both rotating magnetic-platter hard drives and solid-state drives) which can record information and retain it after power is lost.

A modern computer has a very small amount of “firmware” which is like storage (non-volatile) but treated as if it were non-writeable non-erasable memory that the computer can direct execute. The program in that firmware is just enough to read more software off the storage system and put it into memory ro be executed. That software, read out of storage and put into volatile memory to be executed, is the operating system, such as Windows.

The operating system reads other software – user applications – into memory and executes those for the user to use.

The applications read data out of storage or other sources (user input devices, the Internet, etc.) to work and store the modified data back into storage or the network.

Try to imagine the concept of a latch; suppose you have a wire that goes though a switch to a lamp; when you switch the lamp on, it stays on until you switch it off (and as long as there is a continuous supply of power).

Now suppose you add a little electric motor that can move the lever of the switch without you needing to use your finger; a signal sent to the motor can be used to store a single ‘bit’ of data - zero (lamp is switched off), or one (lamp is switched on).

Something like this can be constructed from tiny, solid-state switch-like components instead of large mechanical switches.

RAM disappears when the computer is turned off. While on and powered, as I understand it, RAM holds electrons in miniature little loop-cells that it refreshes periodically.

There is, traditionally, a small segment of EPROM that would contain enough code to be able to identify the hard drive, load some bootstrap code from it into RAM, and execute that on startup. I assume that, that’s been replaced with something more modern but I’d expect that the basic setup is still conceptually the same.

Otherwise, you need to store data on a disk drive or some other type of permanent storage, e.g. punch cards in olden times and flash memory in more modern times. I believe that flash memory may be descended from EPROM.

I think you’re right - EEPROMs typically have to have their data written all at once in one continuous operation; flash memory is (as I understand it) like an array of EEPROMs with a controller that manages how the data is written to each of them.

Main memory (RAM) is made from a large array of capacitors. Capacitors store a tiny bit of electricity, like a small battery. The memory stores a 0 or 1 based on the electricity there.

However, capacitors are leaky. So the computer refreshes them periodically when it’s turned on. It reads the value before it’s fully degraded and writes a fresh version. Like topping off a bucket of water with a leak in it.

If the computer is off (truly off, with no power or battery), then it no longer refreshes and the data is lost. Hard drives use a different method of storing data (with magnets or a special kind of electrical storage that doesn’t degrade) so that they can retain data without refreshing.

NVRAm - like found in phones, USB drives, and now in SSD dirves - is basically capacitors that can store a seting (on or off, charged or not) for a very long time. Read- is the capacitor charged? Write - charge the capacitor(1) or drain it.(0)

NVRAM is actually made from floating gate MOSFETs, not capacitors. The transistor is driven into a 1 or 0 state, and the gate is protected by an insulator so the state doesn’t change until you apply a new votlage.

There are two basic types of RAM memory in most devices: Static and Dynamic. Static RAM requires power to maintain its states, but does not require a periodic refresh cycle. Dynamic ram has to be refreshed constantly or it will lose its change and values. NVRAM would be flash drives, SSD disks, etc.

Electricity that is flowing is called “current.” The usual definition of current is “charges” (usually electrons) that a moving. But, charges don’t have to move - they can be stationary, and still be detectable. Memory (RAM) uses charges stored in capacitors (cells) to indicate which cells are “1” and which are “0.”

RAM design is very sophisticated, and the cells are extremely tiny, so the amount of charge stored doesn’t have to be very big. This allows very dense storage (billions of bytes) and very fast speeds (billions of bytes per second), and very low power.

This might need more explanation. If its not magnetically stored, and not stored by tiny capacitors that get periodically refreshed…how is it stored?

My new computer has ‘solid state’ storage, no disks, no plattens. I’ve got ‘flash’ (USB) drives that are over a decade old that still have useable files on them and no electrical connection to refresh.

How is this info stored without magnets and refresh?

Let’s back up a step. One very important concept in computing is layers of abstraction. A computer involves many, many layers, and if things are working right, you can be an expert on one layer, while knowing only a little bit about the layer above you and the layer below you, and almost nothing of the layers beyond that.

What you’re asking about here is at a very low layer of abstraction: Electrons flowing through wires. But once you create that layer, the next layer above doesn’t need to know how you did it. It just needs to know things like how quickly it can access the memory, how much time it takes to write, and maybe things like how reliable the memory is.

This is important, because over the history of computers, many, many different kinds of devices, working on many, many different principles, have been used to make memory. Every so often, they come up with a new one, and implement it… and most of the higher layers neither know nor care that anything has changed under the hood.

There are very thin, highly-insulating layers in each memory cell. The insulation is so good that almost no electrons can penetrate the layer, even after decades. When a cell has its state changed, electrons need to be transported through the layer, and this is done by increasing their energy (voltage) briefly. This provides enough energy for electrons to 'tunnel" through the layer. When the voltage is reduced, those electrons are trapped, resulting in “permanent” memory storage. The erase and write cycles are not symmetrical - entire “pages” of memory are erased at a time, but individual cells can be written.

Hi, so it seems that, roughly, the consensus is that while there is no power or energy running the computer at large, there is some or is a isolated aspect of the computer when it’s shut down that is still energizing it, at least the memory part?

EDIT: Sorry, didn’t mean to reply directly to you Sam_Stone, but it isn’t letting me delete the post so while my response may be particularly directed at you, that was not done with intent :slight_smile:

Nope.
Just like the is no power going to as USB flash drive when it’s in your pocket.

No. Various forms of long term memory do not require any energizing to store data.

From an abstract point of view, persistent memory used in a computer - whether flash ROM, or magnetic storage is not any different to writing something on a piece of paper. There energy is used to change the physical relationship of things, whether the location of electrons, orientation of magnetic domains, or fragments of carbon on a page. We just use a device where the changes stay put for a reasonable amount of time.

A segment of flash ROM is rather like an Etch-A-Sketch. You store an image by moving little fragments off of the page. When you want to store a new image you reset the entire page, returning fragments into all the places they once were. For a page of ROM, you write the data by moving electrons out of some locations. If you need to store another slab of data, you move all the electrons back, and then proceed to cut another page of data into it, moving more electrons about.

If you get deep into the question, there is a change in energy of the system. Less or more entropy, more or less energy, although the exact manner you might calculate this is open to debate.

With Flash memory, the device is not “still getting power.” But they are using electrons. The electricity is stored in a capacitor with an insulation layer that keeps it from discharging. Think of it like static electricity, but you never touch anything metal.

With old fashioned hard drives (and even floppy disks), it worked basically like writing on a cassette tape. The electricity is used to move little tiny magnets, which then stay in place.

The former can eventually lose charge, but it takes decades. But the latter only tend to last 10-20 years as well, unless they are stored and not used. But even they will degrade eventually.

How the f*** do they work?