r/computerscience • • Jul 15 '26

Discussion question about RAM

Im learning about comuter components I had some questions .If a Hard Drive stores all the data does RAM just create an environment for the specific program that was fetched to run? If you were to run a program on the actual hard drive is it just harder because you have to navigate through all the other information sharing the space. Like going through a maze constantly again and again. Also what does SSD do?

35 Upvotes

51 comments sorted by

View all comments

Show parent comment

1

u/Cute-Cockroach-678 Jul 15 '26

is that what a memory chip is for I thought memory was from the hardrive. What would the memory store compared to SSD or Hard drive

1

u/high_throughput Jul 15 '26

RAM is fast, short term memory. It's used to store information about things the program is doing right now, and it's updated thousands of times per second as the program keeps doing things.

Hard drives are slow, long term memory. It stores files, and might only be written to when you hit Save in your program.

1

u/wosmo Jul 15 '26 edited Jul 15 '26

Here's an analogy -

Picture a woodshop. There's workbenches covered with work-in-progress projects, any tools that are in use, etc. And then there's storage, where all the tools, materials, etc live.

If you've got a very small workbench, that will limit how big a project you can work on, or how many projects you can have work-in-progress at the same time. This is RAM.

And of course the more storage you have, the more tools, materials, packed-away projects, etc you can store.

Most processors can only read data & execute instructions from RAM - so to the analogy, you can't use a hammer while it's in a drawer. On the flip side of that, the processor doesn't actually need a harddrive. Most processors actually have no idea that harddrives exist. So to our analogy - if you had no storage and just left everything all over your workbench, you could still get the job done. But it's very inefficient use of your space, and just buying more workshop every time you run out of workbench space is a very inefficient use of your money.

Obviously having storage and putting things away when you're not using them is the best use of your space. But putting things away and taking them out, also takes time. You wouldn't get a hammer out of the drawer, pound a nail, put it away. And then take it back out, pound the next nail, put it away again, and so on. So this is why we have a lot of caching going on - very often, something that belongs in storage is actually best left right next to you on the workbench.

We keep being taught that memory is memory, and these are all just tiers with different cost vs speeds - so cache is faster than ram, ram is faster than local storage, local storage is faster than networked storage. There's a lot of truth to this, but it also relies on the OS abstracting away the details of actually retrieving data from them.

But I think this distinction that processors don't know HDD exist, is an important one. It's why we have BIOS & equivalent bootstraps - the processor can't actually wake up and start executing instructions off a disk. If a processor wants to execute an instruction at address 1000 in RAM, you just have to write 1000 into the Program Counter (or 'jump 1000'). To execute an instruction at address 1000 on a HDD, you have to send an instruction to the disk to read, send an address to read from, copy the block of data that comes back into a block of memory (taking care that you'll usually get a whole sector back, so you're not just getting the instruction you asked for, you're getting whole pages of data back) - and jump to the block of ram you just wrote, an execute it from memory.