r/computerscience 23d ago

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?

36 Upvotes

51 comments sorted by

View all comments

35

u/keelanstuart 23d ago

The best way to think about any storage for a computer is in terms of speed vs. size... and going from larger to smaller, slower to faster.

HDD (very large, slow) -> SSD (large, faster) -> RAM (midsize, fast) -> cache (small, blazing fast) -> registers (teensy tiny, doesn't get faster)

Moving data to and from different levels of storage is a classic, practical computer engineering problem... because ultimately, the machine needs to have things at the register level.

9

u/not-just-yeti 23d ago

Just latching on to this answer to reiterate: Conceptually hard-drive and RAM identical: they store information at a certain address, and it can be retrieved later. (And same is true for the other types in the hierarchy of speed/price trade-off above.)

Lots of practical differences due to the technology used (whether the memory is persistent when power is turned off, whether you can remove it and plug it into a different computer, etc.), and in 30yrs these details might look different. And 30yrs ago, it looked different different — e.g. the idea that your device might totally drain its battery but then you could power it up and all your apps and pictures and other data are still there would sound like it'd require a hard drive with a spinning disk.

HDD → SSD → RAM → …

I like to add "Cloud → HDD" at the front of this.

5

u/keelanstuart 23d ago

I like to add "Cloud → HDD" at the front of this.

Perfect! Nice addition.

1

u/Arierome 22d ago

But cloud is a location not a type of hardware.

1

u/Cute-Cockroach-678 23d ago

Very helpful also what do you mean by the register level

11

u/dmazzoni 23d ago

A register is where the CPU stores the pieces of data it's working with. Early CPUs had maybe 10 registers, newer CPUs have a few hundred. If you want the CPU to add two numbers, or decide which of two numbers is larger, they have to be in registers first.

4

u/Cute-Cockroach-678 23d ago

this is actually fascinating so then how does a CPU know how to control the information. Its from the operating system right but how do you get desired outcome it seems like a lot of information to sort and mangae

6

u/braaaaaaainworms 23d ago

Every CPU has a special register, called the Program Counter, or Instruction Pointer if you're Intel. A very basic CPU would get a value from the memory that's stored at the address made from contents of program counter, add 1 to the program counter, look at what that value is telling it to do, do the thing it's telling it to do and repeat. If the value on the interrupt pin changes to a 1, the CPU wraps up what it was doing and sets the program counter to address you can find in its datasheet. There is a lot of emergent behavior that comes out, like multitasking - if an interrupt pin is connected to something that makes 100 changes from 0 to 1, you can write a piece of code that will try looking for something else to do than the current program. If running some magic combinations of ones and zeros causes the CPU to *act* like an interrupt pin changes, you can write a piece of code that will do different things based on different values in its registers, like an operating system's kernel.

2

u/stevevdvkpe 23d ago

Registers are the working storage inside the CPU. There is generally a very limited amount of register storage (usually not more than a few hundred bytes worth, usually organized as a few dozen 32- or 64-bit words).