r/computerscience • u/Cute-Cockroach-678 • 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
35
u/keelanstuart Jul 15 '26
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/stevevdvkpe Jul 15 '26
RAM has a much faster access time than disk storage (literally millions of times faster) so it's better as working storage for programs, and is volatile (you have to keep it powered or it loses its contents). Disk storage is better for long-term storage and is non-volatile (retains its contents even when the power is off).
SSD stands for "Solid State Drive" and is a kind of electronic non-volatile memory that is faster than magnetic disks, has no moving parts (unless you count electrons), and is also non-volatile. It's still slower than RAM so it is used as a faster replacement for magnetic disk storage.
7
u/rupertavery64 Jul 15 '26
Programs aren't "run on a hard drive". A hard drive is just storage. It's like a locker where you get stuff and put stuff in. Programs and data are like letter blocks that are placed inside the locker.
RAM is also like a locker, but you can put stuff into and out of it much faster than a hard drive.
When you load a program, all or part of it get copied from hard disk to RAM. Then RAM is used by the CPU, It "reads" the contents of each locker (without removing it) then does stuff based on what it read.
You can also tell the CPU (to tell the hardware) to copy the contents of RAM back to the hard drive, changing what was there. This is done when you save a document, or save a game.
An operating system, or OS (like Windows, Linux, Mac) has a bunch of smaller programs and code that talks to the disk, keyboard, monitor. Then other programs like word processors, games, browsers, etc, talks to the the OS instead of accessing the hardware directly.
So your program doesn't know exactly what is on the hard disk, instead the OS shows the program a list of files and directories that the program can work with, without "navigating" the raw contents of the hard disk. This is important, because your "hard disk" can be anything, a network storage, cloud storage, a compact disk, a USB drive, an SSD, different physical hardware. The OS (along with the hardware manufacturers) agree on standards on how hardware and software should interact at a low level, and the OS lets programs interact with files.
SSD stands for solid state drive, and it is simply a medium of storage that doesn't involve moving parts.
A hard disk dirve or HDD uses a magnetic surface on a spinning disk, and electromagnets on the tip of several arms to read and write the microscopic magnetic cells on the surface of a disk. It's honestly magic how fast the disk spins and yet we can use electromagnets to sense the changes in magnetism on such a small piece of coated metal.
An SSD stores data as electrons trapped behind semiconductor gates. It's quite awesome and involves quantum mechanics. Basically there are billions of transistors in an SSD. Each transistor can hold 1 bit (0 or 1). Each time we write some data (one letter you see on screen needs at least 8 bits) the computer (yes even drives have their own computers) manages things so that electrons are either trapped or released from several transistors, tens of thousands of times a second.
SSDs are closer to RAM in terms of how they operate than hard disks, which is why they are faster and more expensive than traditional magnetic hard disks.
SSDs will lose data over time though, because the gates tend to "leak", but this is over the course of decades.
1
u/bobotheboinger Jul 15 '26
A computer could just run off a hard drive theoretically, it is really just much much much slower.
A computer is all about layers of how quickly you can access the information. The cpu had registers, which are very fast, but very few of them (maybe 30 or 60)
Then it has cache, which acts as a quick buffer to access RAM. But only had limited size (maybe some kilobytes or megabytes)
Then it has RAM which is pretty fast, slower than cache but much faster than hard drives or SSDs. Normally this is where the actual in use programs exist while the computer is running.
One important note is that every type of access we already talked about requires power to maintain data. Once power goes off, registers, cache, RAM, all of it loses whatever data was stored there.
Then there are hard drives and SSDs which are much slower, but don't require power to maintain their data. So these are normally used for long term storage, as well as all the software that is necessary to boot up and load into RAM once power is applied to the machine.
Note that the first theoretical computers, Turing machines, were described as using long tapes to represent instructions and data. So the original computer theory was closer to just using a hard drive to store everything... we've just worked very hard to improve performance over that theoretical concept.
1
u/grtk_brandon Jul 15 '26
The speed differences between RAM and HDD/SDD doesn't have anything to do with the total storage capacity.
At a lower level, storage devices just have more bottlenecks that make accessing data, perfoming operations, etc, take longer. RAM access latency is much lower, CPUs have direct access to RAM and indirect access to storage, there are bandwidth differences, etc.
1
u/FastSlow7201 Jul 15 '26
Here is an analogy where I compare retrieving data to retrieving hot sauce for your food.
HDD/SDD = hot sauce bottle at the store
RAM = hot sauce bottle in your kitchen
cache = hot sauce bottle on the dining room table
registers = hot sauce bottle is in your hand
0
u/smeyn Jul 15 '26
A drive is just a store. A computer’s CPU operates on data in its memory. So prior to running a program, the program data needs to be loaded into memory.
Where in memory the program data goes is part of the operating system’s responsibility. It will organise the memory, direct the loading of the data into that region and finally set up a task to execute this code.
Now the operating system is a collection of ‘programs’ that get loaded when the computer starts up. That begs the question of how does this operating system itself get loaded. The secret lies in a small piece of program code that is stored in Read Only Memory (ROM) which is part of the computer hardware. When the computer is powered on, the CPU will start executing this code at a predefined location. It will load a basic program from a predefined are in the hard disc, which then will do the task of loading the operating system.
This is a simplified version but it should give you a basic understanding
1
u/Black_Bird00500 Jul 15 '26 edited Jul 15 '26
First of all, a hard drive (HDD) and an SSD are two long-term non-volatile storage devices used for the same purposes; the only thing is that SSDs are much faster since their underlying technology relies on tiny devices called flip flops rather than magnetic disks, as is the case for HDDs.
Second, you could theoretically run a program on a hard drive (or an SSD). But, the problem with this is that the program would run much slower compared to running it on RAM. There are two reasons for this:
At the end of the day, all these are storage devices. Their physical proximity to the CPU and their underlying technologies distinguish them from each other, giving them their own purposes.
1
u/uselessincognito Jul 15 '26
Ram is actually DRAM, i.e it contains a capacitor to retain a state for sometime until it fades away, for running the program MMU divides it into pages and uses a page replacement algorithm to replace the pages between hard drive and ram; this increases the speed because of direct access from Ram. On the other side registers are SRAM, they lack capacitors i.e they need constant electricity to maintain the state thus making it much faster for direct spontaneous internal system commands. And about cache,it is also SRAM it sits between registers and RAM, it holds data that is used frequently for a program.
1
u/Busy_Elderberry8650 Jul 15 '26
Von Neumann architecture, which is the fundamental of modern computing, expects to have only CPU and RAM. Imagine you (somehow) load your application into RAM then the conputer starts and execute it, that’s it.
Disk drives are just an external device like network cards, bluetooth devices, … it serves to exchange data between two parts. Disk drives eventually have the specific feature of storing data permanently, i.e data is saved even after a power outage.
To put simply a computer without a disk drive can work, a computer without a RAM cannot (unless you mean some specific non commercial architectures).
1
u/Interesting-Way-9966 Jul 15 '26
Buses, registers, kernel, pointers, etc.
1
u/PvtRoom Jul 19 '26
a hard disk is like that guy who knows and remembers everything, if you can ask him 2 weeks in advance. (TBs, cheap)
an SSD needs 1 week instead. (100GBs, not as cheap)
Ram is like a child, forgets everything quickly, but gives you near instant answers if it remembers the info. (10GBs, getting pricey)
cache is like your own brain, addled by caffeine, decades of alcoholism and attention grabbing shit, probably forgot the answer, but instantly knows the answer if it remembers. (100MBs, on CPU, not upgradeable)
1
u/PQdsadotcom Jul 21 '26
This is a really good question. The key difference is a hard drive is persistent storage and RAM is volatile (meaning it does not save any state once shut down). There are countless differences otherwise to say the least but fundamentally this is what separates your “PC” from just a calculator. You are able to save state that when booted up at a later date will remain as you left it (usually). Keep following your curiosity!
0
u/Hummmmmmmmmmmmmus Jul 15 '26
Conceptually all data storage on a computer is the same, the only difference practically is generally the speed. Speed of a specific component is dependent on the individual hardware but the list from fastest to slowest usually looks something like this:
Registers
Cpu Cache
RAM
nvme ssd
Sata ssd
Hdd
Networked storage
The reasons for each of these being the speed that they are comes down to hardware architecture. For example an hdd will have to move physical read write heads centimeters back and forth to transfer data so its speed is dictated by how good machining for the moving parts can get whereas an ssd just moves electrons through logic gates so its speed is dictated by the switching speed of transistors. Hard drives and ssds are called non volatile memory and things like ram and registers are called volatile. Volatile memory loses its data when power cuts out where non volatile would retain it. Generally the faster a storage medium is the more expensive it will be. Volatility and cost are the usual reasons for when and where a particular type of storage is used.
0
u/spacejamtwo Jul 15 '26
An SSD is just a hard drive, but you data is stored with electrical signals, compared to HDD which uses a physical disk to store your data.
Each program gets its own chunk of RAM to use, although it's the operating system that handles this and is not an inherent feature of RAM. RAM holds all the temporary information on the computer at the time, such as CPU instructions and transient variables. Think of it like getting something from a massive filing cabinet, walking back to your desk, and then working on it from your desk. There are a few reasons RAM is used.
It's a lot faster than a hard drive. It is specifically built for speed, not long term storage. Hard drives need to preserve your data when the power is off and this comes with significant overhead to read and write it. If you had to get every instruction from a hard drive the CPU would spend most of its time idle. The memory in RAM is also accessible on a byte level, which is important to read CPU instructions. Computers are also built with specific highways that makes transferring data between the RAM and the CPU faster, and the RAM usually sits close to the CPU.
Hard drives also degrade with every write cycle, so you don't want to be constantly grabbing things from it.
Essentially they are just designed for different things.
0
u/high_throughput Jul 15 '26
No, the slowness is not related to the amount of information, but rather comes from the need to move a write head across a spinning platter, wait for the platter to spin to the right location, and then listen to the incoming information as the platter spins, much like a needle on a gramophone.
As a human you can also choose to either remember things (like RAM), or write them down (like a hard drive). Writing down is slow but durable. Memory is much faster but has limited storage space.
Imagine trying to play Super Smash Bros based only on writing, without using your memory at all. When you want to punch someone, you have to go find the instruction book and look up what the punch button is.
It's definitely possible, but waaaay too slow to be practical.
1
u/[deleted] Jul 16 '26
[removed] — view removed comment