r/computerscience • • Dec 30 '23

WTF does ram actually do?

I know that RAM stores data for quick use for the CPU. But I want to know more, what does RAM actually do when its storing data. Like when I'm playing a game is RAM responsible for keeping track of how many bullets I shoot. If there are any game developers reading this please let me know. What kind of information does RAM store and how and when does it use it. The main thing I use my pc for is gaming and recording/video editing so how would RAM play a role in those things?

260 Upvotes

97 comments sorted by

View all comments

1

u/slxshxr Dec 30 '23

I might say something wrong here, i'm not entirely sure about some details as i had system architecture on university some years ago.
Processor uses something called cache to save data. You can google what cache is more precisely.
Now there are limitations to how fast you can access data. There are some levels:

  1. CPU registers - very small, very fast
  2. L1, L2, L3 cache - increasingly bigger and slower (L1 being fastest).
  3. RAM
  4. Local disks
  5. Web servers etc.

Now - CPU register, L1, L2, L3 Cache are places where CPU can instantly look for data. It's very small so only frequently needed data is stored there.
RAM - Random Access Memory. Word random is crucial there, because there are things called "misses" - cold, capacity and conflict misses if i remember correctly.
Disks and webservers are way way way slower. To put into perspective - RAM is ~30x faster than Disks and L1 Cache is 10-100x faster than RAM :).

Basically RAM is a bigger cache memory that allows you to store data that are not needed almost all the time but you don't want to save it on disk. (for example how many bullets you shot), where faster caches are mostly used by operating system things.

If you want a better explanation than mine (not hard to do lol) it's better if u read about L1, L2 and L3 cache - then you will understand RAM

3

u/slxshxr Dec 30 '23

PS. I recommend "Computer Systems: A Programmer’s Perspective" book, it's quite good and easy to read.

2

u/TimedogGAF Dec 30 '23 edited Dec 30 '23

I do not recommend it as "easy to read". It explains concepts in the most rigorous way possible without presenting more human readable simplifications or explanations, using complicated and super abstracted Riemann sum notation to explain things that could easily be explained in a sentence or two.

There were also multiple times where large logical leaps were made in explanations, that in order to cross required you to remember some small piece of info that was mentioned a single time like 70 pages ago.

Write Great Code Vol. 1: Understanding the Machine is significantly easier to read and is recommended for beginners. It condenses the long, abstracted equations from Computer Systems and states the concepts plainly and concisely, the way actual programmers in actual programming jobs communicate.