r/computerscience • u/TranslatorParty4662 • 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?
94
u/FantasticEmu Dec 30 '23
The entire process is stored in ram while it’s running m. Your game is a process, your editing software is a process, your operating system is a process
10
u/Pedro73376 Dec 31 '23
This is the most general and correct answer, but I’ll add that not only process ate stored in RAM, but also files, and directories are also files underneath, so when some line of code request something from IO that is not in l1 cache, it will require to the SO, that will cause the process to be put in hold and the processor is freed to do something else while the data is being retrieved and stored in ram, tipically the ssd’s and hdds are slower then cache in two orders of magnitude. But that is it, instructions and data are stored in RAM.
5
u/jgames09 Dec 30 '23
It can be stored partially, divided in pages. Otherwise no way would you be able to run games such as CoD lol
6
u/PaulWard4Prez Dec 31 '23
The CoD package is huge, but it’s not all in memory at once. Only the elements that are relevant to your current game context will be.
9
u/FantasticEmu Dec 30 '23
Not sure what you mean. A page is in ram. If you run out of physical memory it’s possible to cache pages in virtual memory but I believe that is outside of the scope of discussion and usually a scenario to be avoided.
The running process is what is memory while it’s running . That doesn’t mean that it has all of the data in whatver parent directory the binary is in.
41
u/P-Jean Dec 30 '23
RAM is volatile memory that processes use to store and access information often while waiting for their turn on the processor. This info needs to be written to nonvolatile memory like your hard disk if you want to save it once the power is shut off. The more RAM that you have, the more processes you can run. They are still limited by their turn on the processor though.
9
u/siddeslof Dec 30 '23
To elaborate on that last point I have 64gb of ram and a decent CPU which means I can store that 64gb of data but still have to wait for my CPU to retrieve the data and execute any tasks before and leading to that data retrieval
1
u/P-Jean Dec 30 '23
64gb! I’m envious haha.
3
u/FluffyProphet Dec 31 '23
Ram is dirt cheap again. I had 16 and it was staring to become a problem for work. I upgraded to 64gb of faster ram than I had before for around $100. One of the best computer investments I have ever made.
→ More replies (2)3
1
u/LifeHasLeft Dec 31 '23
The computers at my office all have nearly 100 GB of ram! They are beasts but they are being used for heavy computations
3
Dec 31 '23
If theoretically we are able to achieve hard disk data read/write speeds comparable to RAM, would that eliminate the need of RAM itself?
The only advantage RAM offers is high speeds for data read and write. If a hypothetical memory device has the same speeds wont we just create a partition and run with it?
2
u/TheCloudfather Oct 05 '24
Yes, that would generally be correct. There are RAM Drives that allocate a certain amount of RAM to be used as a very high speed storage drive, and there is Virtual Memory which allocates a certain amount of storage drive space to be used as additional RAM. The tradeoffs are pretty severe though, a RAM Drive is going to be very small in size (a couple of GB max) and virtual memory is going to be very slow.
There are more differences between a disk drive and RAM that are being glossed over though. RAM is connected directly to the CPU by a high speed bus, so the CPU can read and write directly to memory locations in the RAM. Disk drives are not directly connected to CPUs, they have a separate controller which is in between them and the cpu that coordinates communication and is a bottleneck as far as speed is concerned. So in a nutshell, if a theoretical high speed disk drive was available we wouldn't be able to use it like you are describing, a whole new computer architecture would need to be designed for it.
→ More replies (1)1
u/P-Jean Dec 31 '23
That’s a really good question. That’s a bit beyond my understanding, but I know that you can use your HDD as RAM in the form of virtual memory. I think it’s limited by the bus speed to the drive. I’ve wondered why SSDs aren’t used in this way. A partition, like you said, would make sense if the speed is comparable to stuff like RAM and cache.
Maybe someone here who deals more with hardware can chime in. I only know the basics of memory management from a software perspective, and even then, there’s always exceptions.
2
Jan 01 '24
Yeah I was actually thinking of VRAM, only with entire RAM in memory.
Maybe the very frequent read/writes in SSD would potentially decrease the lfiespan and won't be that fast?
→ More replies (1)2
u/purepersistence Dec 31 '23
RAM is volatile memory
The most common type of RAM is dynamic and therefore volatile like you say. Static RAM is not volatile. It keeps its content after power-down/restart. Dynamic RAM is slow and cheap and the most common form. Static RAM is fast and expensive. Dynamic RAM is based on capacitors, which loose their charge over time and hence the need to keep refreshing the memory by recharging the capacitor. Static RAM is based on flip-flops which retain their state after powered down.
25
u/belegdae Dec 30 '23 edited Dec 30 '23
I’m a games dev, hopefully this will help -
Every part of software, and the data used by it is encoded (or converted) to a binary format - 0’s and 1’s, or on’s and off’s called bits. A simple colour uses a set of 24 of these bits to represent a single colour. A number can be stored this way too, as say an integer or floating-point decimal. Whatever the data, there’s a way someone has come up with to store it as bits.
Where ram comes in is in the middle of a bunch of different ways to store this data that trade off performance against density.
One of the fastest is a tiny bit of storage called L1 cache that’s actually inside the cpu - this holds some recently used data inside CPU - it is crazy crazy fast. On the opposite side are things like tape drives for backups, these have huge capacities but are millions of times (if not more) slower. In the middle we have hard drives, faster SSD’s, and faster still RAM.
RAM is where data and software is loaded from disk into a smaller but faster to access place, and is loaded into the L3, L2 and L1 caches of the cpu to actually compute.
11
u/Mabenue Dec 30 '23
This is wrong, the current operation is not held in the L1 cache. It behaves closer to system memory than what you’re describing. Current operations are held in registers within the CPU.
4
9
u/ChrisGnam Dec 30 '23
For a brief simplification, computers utilize a memory hierarchy to keep things organized in a way that balances how easily the CPU can access stuff, and how often the CPU needs stuff. You can think of this as the following 4 tiers:
harddrive/SSD: This is where you keep stuff for long periods of time. These types of storage have a lot of space, and can hold stuff for years, but the CPU is slow to read things from them.
RAM: this type of memory is much faster for your CPU to read from, but it can't hold nearly as much and it isn't capable of storing data when your computer is powered off. So your computer will load stuff from your harddrive/SSD that you might need soon so that it can quickly access it when the time comes. (This is what part of what is happening when your video game is loading a level or booting up)
Cache: this type of memory is physically a part of your CPU. It is even faster than RAM, but way more limited. This memory is used for stuff the CPU is dealing with imminently.
Registers: this is the actual parts of the CPU that get changed/modified by the CPU doing stuff. So data here can actually be updated by the CPU. This is "memory" for what the CPU is dealing with right now.
So in short:
Your installed video game is permanently saved to your harddrive/SSD. When you boot up the game and load a level, everything that the video game might need to play that level is copied from your SSD to your RAM. Then at any moment in time as something is needed, it is copied from RAM to your CPU's cache. And once your CPU is ready to do something with it, it's moved from the cache into some registers so the CPU can actually do stuff with it. This happens millions of times of second as your CPU needs different things.
2
u/Mack2Daddy Dec 31 '23
So I would ELI5 this as: you’re ‘crafting’ stuff and you have a crafting table and a closet full of boxes of crafting supplies. Walking from your table to the closet to take something out of a box and going back would take ages so:
When preparing to craft (run processes) you take a few boxes (RAM) from the closet (NVM) that you know contain things you will need and you put them on (or next to) the table.
From those boxes things are taken out and put on the table (caches), where your hands (registers/working part of the CPU) can reach them.
That way, when you’re crafting, you don’t have to leave the table and your hands don’t have to stretch or search for the things you need and the process is slowed the least amount possible.
1
4
u/hotel2oscar Dec 30 '23 edited Dec 30 '23
If you think of your computer like a workshop:
A hard drive is like a warehouse. Massive storage, but a pain to get things from.
RAM is the storage closet in the shop itself. Everything worked on in the shop comes from here. If it isn't there they run out to the warehouse and restock.
The workbench is the memory in the CPU. This is what is actually being worked on.
Back in the day the CPU only had registers, and no cache. RAM was that cache. It still serves its purpose of being the intermediary between the permanent storage and the CPU, but the CPU has more internal layers to buffer the need to access RAM directly.
With electronic memory you have some tradeoffs. The faster it is the more expensive it is. So permanent storage is cheap but glacially slow compared to the expensive but instantaneous registers. Everything in between is somewhere on this spectrum.
4
u/cv_ham Dec 31 '23
1
1
u/drunk_kronk Dec 31 '23
Yes, this video does a really good job of explaining what is actually happening.
3
u/arkane-linux Dec 30 '23
Everything you interact with, everything you do and all the logic behind it is stored in memory.
Whenever the CPU does any type of calculation it may first have to request the relevant data from the system memory, the CPU itself has very limited memory storage capacity, only the most commonly accessed data it will keep on-hand.
3
u/proverbialbunny Data Scientist Dec 31 '23
A good metaphor to explain this is imagine software is items on your desk. Each item has a purpose. How much ram you have is the size of your desk, how many things you can store on your desk at any given time. How much hard drive you have is storage bins. If what's on your desk is paperwork, then your hard drive is a filing cabinet.
When needing to find something in storage it can take a while. When needing to find something on your desk it's quite quick. When it's actively in your short term memory, in your head, it's in the CPU itself. CPU has its own memory too.
2
Dec 30 '23
everything the program needs to run and everything you're seeing on the screen would be on the RAM while you're doing anything. once you quit (if what you're doing is savable on your computer) everything will be stored in the HDD/SSD.
so yes, all the graphics of the game (including bullets), all the actions you take, and all the background systems needed to run the code of the game are constantly on the RAM while you play.
2
u/Twt97 Dec 30 '23
Its the memory hierarchy. You can retrieve instructions from fast memory like registers/RAM/SSD alot faster than slow memory like hard drives. The tradeoff is that fast memory is alot more expensive.
For example you dont want to store an entire backup of your entire computer on a fast memory like an SSD because you are probably hopefully never going to have to use it in your life.
I actually recently decided to move spotify from my 223 GB SSD cause it was almost full to my huge 1000 GB hard drive and the only thing that changed was that spotifty now takes 3 extra seconds to start. Not a big tradeoff since i only have to open it once during the day.
2
u/titus605 Dec 30 '23
Your entire game is loaded onto ram. All the data that the game needs is on the ram. However, there's some things in the game that are needed more than others such as intense combat scenes where a bunch of objects, i.e., the location and properties of the bullets, characters, weapons, are crucially needed to keep the game mechanics working smoothly compared to a single tree 2km away that's barely visible to the player. The more "needed" objects are used more quickly, and their data is changed more often. However, the ram that you see in task manager isn't fast enough for the raw data exchanges, so extremely fast ram called the cache is built into the cpu. It can keep up with the raw reads and writes of the cpu and be used to store the many numbers and calculations that pertain to the object stored in the ram. Once the calculation is done, it gets spit back out into the ram to be stored for later use. However, there's also virtual memory, which is used for when the physical ram gets full and the machine needs more ram, and that's when a tiny part of the disk is used as ram.
1
u/Mack2Daddy Dec 31 '23
Can I ask: the virtual RAM (is this the same as the page file?) is much slower than actual RAM then? Why does it exist, instead of getting more RAM?
2
u/EducationalMacrocosm Dec 30 '23
Something I want to add that I feel others are missing, though great explanations, is that, in laymen terms, these things like "bullets shot", are not all independently stored by themselves in the RAM. It's not like bullet ID 13402 shot on X position of Y map by Z player, etc. It's just the variables that make the game run/ have purpose are being stored, typically as counters, and other data structures. For example, the bullet being shot isn't really of interest once you click shoot. There are just a few variables from that action being stored. For simplicity sake, as an example, you click 'shoot' and most likely some of the variables being stored and used from RAM are bullets_in_magazine = 12 (pretending that's what your gun magazine holds) - 1, then if the target was in the same frame error threshold of where you shot in some specified time frame then player_2_hp = 100 - 20 (or however much damage is decided that a bullet on a specific portion of the players body does.)
Then you have other things like hp potion for example, or a med kit that your player uses. This most likely is stored in the RAM under your player as a count. Then you use it by performing that action, and it adjusts the variable that contains your hp accordingly.
It's just a bunch of variable tracking, that, when put together, looks like a fluid game.
2
2
u/AdjustedMold97 Dec 31 '23
Think of your persistent storage (SSD or HDD) as a math textbook, and yourself as the CPU. You want to solve some of the problems that are in the textbook, but you can’t just do it all in your head. So, you’ll take some scratch paper and do your arithmetic there. RAM is pretty much the scratch paper of a computer, it’s a place where data is stored until it is no longer needed there. If you’re really happy with your work, you might want to write the answer in the margins of your textbook, that would be like saving a file you’ve edited. Hope this helps and isn’t terribly confusing!
1
2
u/ForlornMemory Dec 31 '23
When you open a program, everything that it doesn't actively load, is stored on RAM. Like, when you load a level in a game, that level is stored entirely on RAM. When you load a new level, it loads it from your SSD (or HDD) into RAM, so that the computer can do stuff with it. The thing about RAM is that it's super fast for computer to use it. Thus all active operations are done using RAM.
Here's another example: when you edit video, the whole process will be done on RAM, until you hit the export button, which will load the result on SSD (or HDD).
1
Jun 05 '24
I’m currently diving into the mechanisms of computer systems. From what I’m understanding the GPU pulls information in the program from the hard drive and stores it on the ram for easier and faster access. While the gpu uses the data from the hard drive to run the program. So instead of the processor hard pulling information from the hard drive constantly to update the performance or access data memory frequently it stores it on a temporary drive. For things like online games, I would assume that the game is designed to pull information from the server and locally store it in the ram. Meaning that the program data on the hard drive won’t have as much information to store on the ram but the ram will constantly be updating data to account for the game mechanics. The structure of the program and things like the maps movements mechanics and set data like what items are accessible would be stored in the main program data. Updatable information like what guns you are using how much ammo you have your movement on the map matchmaking and other players information would be being pulled from the server to the ram Drive and being read by the GPU constantly.
1
u/bigboydick1 Sep 26 '24
Does it matter in which order the ram goes back in after taking it out. I’m asking because I don’t have WiFi option any more even tho the motherboard has WiFi antenna on it.
1
u/Dave-James Oct 08 '24
It is a converter that changes that horrible Modem Noise into Easy Listening Music…
1
u/Hopeful_Repair205 Nov 02 '24
Imagine it as how much memory you can comprehend at once, that’s what I think RAM is
1
u/Quiet_Today_1215 Jan 27 '25
Hey, i found this video it explaines everything in a simple way. https://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2Khttps://youtu.be/xR5rw2qaznM?si=-Xoy4-DPb_AbGO2K
1
u/DizzyColdSauce Jan 06 '26 edited Jan 06 '26
RAM is just temporary storage used for quick access. If you open a program or have it open in the background, it will be temporarily stored in the RAM. If a software or program contains or uses more data, it will probably use more RAM as well.
For example, games that use higher quality assets or a higher number of models will use rely on more data at once and therefore more RAM. Your game wouldn't pay attention to the history of bullets you shoot but rather the number of bullets that are currently physically active in the game, plus the bullet's model and textures if applicable. In this case, RAM needs to store game assets so that the game can quickly display and render them whenever they appear in the game. Some game statistics may be stored in the RAM depending on whether the game utilises this, but this takes up the least amount of RAM compared to everything else.
Marvel Rivals uses a butt load of RAM because there are a lot of active, highly detailed character models, effects and maps that need to be used and rendered all at once. And they take up a lot data. So it needs to use up a lot of RAM.
In video recording and editing, a quick reason as to why a lot of RAM is required is because long amounts of high detailed footage simply uses up so much data which needs to be written or accessed quickly. Both recording and editing software have a lot of features which takes up a baseline amount of RAM, and video recording requires the recorded game/software to be stored in RAM as well.
1
u/Rich_Television5266 Jan 25 '26
Okay so is what I know so every time the CPU gets something it takes some stuff along with it to give to the Liam and that is just kind of there and there are many different sections of ram each time it gets closer to the CPU but it has less and when the CPU has to get another thing it checks the Ram and if it gets What It Wants then it takes it back
1
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:
CPU registers - very small, very fast
L1, L2, L3 cache - increasingly bigger and slower (L1 being fastest).
RAM
Local disks
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.
1
u/mikedensem Dec 30 '23
All programs (games, apps, the operating system) need to run in memory (ram). They do not run off hard drives etc.
The physical RAM can be thought of as a huge collection of numbered temporary storage locations for binary data. A program uses free memory to hold values it needs and keeps track of what is stored in the RAM memory by numbered locations (called addresses).
There are two types of memory models used by a program, called the stack and the heap. By default a program knows about its memory requirements for running and therefore requests from the OS the amount of memory addresses it needs. This is called the stack and is a known amount of memory.
The program also usually deals with unknown amounts of data (such as your bullets example) which could be a huge amount of data (user details, game inventory, product details etc). These are unknown when a program starts and are stored in the heap.
The stack and heap are just names to identify different RAM uses. A program won’t start if there isn’t enough free memory for the stack requirements. Whereas the heap requirements (unknown) is where your program can “run out of memory”.
1
u/Dylan_TMB Dec 30 '23
Think of RAM as the same thing as your SSD. But waaaaaay faster. But it needs power to hold information, unlike a hard drive, and it's more expensive per Gb. So hardrives are used to store things long term and RAM is used to hold all the active things.
So faster RAM means things run smoother since all the information states can be changed quicker. And more RAM means more information can be held at once.
1
u/PranosaurSA Dec 30 '23
Unless you are writing a Driver of some sort, you are operating in memory or making calls to the Operating System to load to and from your program's memory to interact with other hardware for you . Its kind of the default "Hardware" that your programs operate on/to.
Your program gets loaded into RAM, it consists of commands to modify information in RAM. Variables of all sorts, integers, floats, and pointers, are stored in RAM.
Now, all this information you have discussed can be stored in anywhere, on a Network Somewhere, on a Disk, in RAM. But, accessing information on Disk or on a Network involves explicit calls to and understand of that information being in those locations through System Calls (Or Drivers if you are in the Kernel). And if your program wants to make decisions or do actions based on its contents, it needs to be read into memory, and anything written to it needs to exist in memory in the first place.
If you wanted to store this information on something called "My Storage Thingy", but your program to modify structures on this disk would have to make system calls to access "My Storage Thingy" drivers. If you wanted to modify information or make decisions based on what the contents of "My Storage Thingy", you would have to read it into memory first. This might be something like an offset and number of bytes. Point is this would be accessed very specifically by mounting it at the VFS and through VFS operations or IOCTL commands.
For Example, Postgres stores its main understanding of the Database Tables and Indexes in Disk. But if it wants to cache this understanding, it stores it in memory. One thing to remember is that these are both very explicit things, Postgres will explicitly store in-memory data structures on to disk with a disk flush with file writes. Its truth is in the Disk but its Cache is in memory.
On the contrary, there are databases with a "memory first" truth understanding, where a side effect is to backup the database into disk, and loading the database involves reading files to load the initial state of the memory database.
Now a potential point of confusion:"Swap" is something entirely different, because everything the programs are operating on in memory are still understood as being in memory. Its the Kernels job to swap those pages in and map them properly to the address when those swapped pages are accessed though. This will automatically trap into the kernel. But do remember that this is entirely different than explicitly storing information on disk or in memory.
1
u/jawadjobs Dec 30 '23
Imagine you have only chrome app in your pc Then ram capacity is equals to how much tabs you could open
1
u/ZayneOnGD1069 Dec 30 '23
Fun fact: the minimum amount of RAM that Windows 11 can run on is 216 MB. But at this amount the OS won’t run properly. Meaning the programs on the computer will open longer than expected, or don’t open.
1
u/Ill_Nebula_2419 Dec 30 '23
Beside all the comments which are right, try to have a look at the little man computer, just Google it and maybe it will make more sense .. it worked for me
1
u/W1nn1gAtL1fe Dec 31 '23
Yes, RAM holds all of the data during program execution that isn't being stored in the CPU registers. It's where your entire operating system and processes are stored.
1
u/reaven3958 Dec 31 '23 edited Dec 31 '23
Pretty much anything not permanently saved to a file somewhere is ram. Anytime you hear the word "memory," almost always its referring to ram. Just about any variable set in a program lives in memory (theyre transient values that don't persist past runtime unless stored in some file like a database, cookie, csv or other document). Work by the CPU, namely the stack (a commom LIFO data structure used, among other things, to manage cpu operations), is kept in memory and tracked by the CPU's stack register. Many database softwares like Redis are memody based, only occasionally (and optionally) writing snapshots to storage (HDD, etc.) and/or just flushing dirty (modified) pages to storage on regular intervals like sqlserver to avoid lengthy write times with every single database change.
1
u/LifeHasLeft Dec 31 '23
So first of all, RAM is special memory that is designed for quick access from the CPU like you said. The problem with just giving programs access to the RAM directly is that they could overwrite eachother’s stored information if they wrote to an address they shouldn’t.
So what do we do about that? First, the OS virtualizes the RAM and tells each open process that it has “full access” to the RAM, and it can write wherever. The process will either write into the stack or the heap, and the OS will translate the virtual addresses the process uses into real addresses for the real memory. The OS will manage all the processes and make sure none overlap. Since the process can’t see where it actually writes to, it can’t do anything malicious.
Now, when the program first opens up it usually has to load things like code, variables, etc. And it is a specific amount of memory every time it opens, known at runtime. Other types of information may need to be stored dynamically, because the program can’t know things ahead of time, like maybe the usernames of the players you are shooting. For that, it requests a space from the OS to keep dynamic information from a space called the “heap”.
The stack and the heap make up a process’ RAM usage. When a process has more RAM utilization than normal, it is because of something dynamic using more memory than is typical. When a process needs to keep information long term, it has to do slightly more complicated operations to pull file information from the hard disk, lock it from any other program’s changes, and then write those changes into the file, finally closing it and letting other programs use it if necessary (this is why you sometimes can’t do certain operations to a file that is opened by another program).
Once the changes are written to the file they are saved permanently. But when a process terminates, any RAM is no longer necessary and goes away. Anything that persisted was saved to disk at some point (in modern times persistence can happen in the cloud, but this is just when things are saved to a remote server’s hard disk instead).
1
u/HotEnthusiasm4124 Dec 31 '23
Ram (if I'm not wrong) stores most of your environment models, NPCs, tools and stuff and all their data (like how many bullets are in your gun, what's the speed of your car, NPC's dialogues)
1
u/Crypt_hash Dec 31 '23
I would explain this that even a person with very less tech knowledge will be able to understand this
Imagine preparing a vegetable salad with limited kitchen experience. You'd gather your tools: a chopping board, a bowl, and a knife, and get your vegetables from the fridge. Picture this: you start by taking a single tomato out, slicing it up on the board, and tossing the pieces into the bowl. Then you repeat this—returning to the fridge for each new tomato. It's a bit time-consuming, right? Now, think about how much quicker it would be if you took out a handful of tomatoes at once, placing them on a tray next to your chopping board. This way, you'd streamline the process, cutting down the back-and-forth, and making your salad prep much more efficient.
In this assumption the cutting board will be your processor, the tomato tray your ram, fridge your external storage device, and bowl your output.
1
u/quichedeflurry Dec 31 '23
Simply put, the RAM is responsible for holding data that is not permanent.
1
u/catsranger Dec 31 '23
Since the game is a program, the OS stores all the info in the RAM. The way the CPU memory is organized is such that the game data being stored in hard disk is first loaded into the RAM (main memory) which further is then loaded in Cache memories since the processors can only work directly with caches and registers and not the main memory. After each calculation, that result is stored back in its designated location in the RAM until it's to be used again for another calculation.
Basically it's tons of calculations and reads/writes happening really quickly. Finally, at some point, the game data is written back to the hard disk to preserve its state.
The RAM is where all the data to be processed is always stored. And since you have less RAM storage than hard disk storage, data is frequently switched between the two using techniques such as virtual memory.
1
u/YakubReddit Dec 31 '23
RAM holds every currently active process on your PC. CPU operates on the data that is present on the RAM, every single thing, from launched browser to a video game, and even processes in the background.
1
u/Fantastic-Hat8118 Dec 31 '23
Think of the ram as the computer's brain, as opposed to, say, paper being the hard drive. This is where the thinking happens. What the computer will do is if you shoot a bullet, the code for how that works is stored in ram. it will go through each instruction, load the necessary operands from the instruction into the cpu's registers (like memory, but even more short-term. usually just for the current line of code.), do whatever math is necessary, and store that back in memory until it needs to calculate more bullet physics. Now that what it was working on has been stored in memory, it's free to work on other things like networking, managing the operating system, saving your game to the hard drive, etc. It's your computer's short-term working memory.
1
u/zeebrow Dec 31 '23
That's quite the question, and your answer will depend on how far down the rabbit hole you're willing to go. Here's a brief attempt at an /r/ECE /electrical engineering answer.
What kind of information does RAM store
Ones and zeros. Each bit in RAM is capable of storing a single boolean value. A chamber in your game's six-shooter might be represented with a single bit. If there's a bullet in there, we say the "bit is set." That's a boolean 1, or logically "True". If the bit is "reset", that's a boolean 0, or logically "False". So your fully-loaded gun can be represented by
111111in RAM.
and how
Bits are represented by the presence (or absence) of electric charge (i.e. current), which is something we can physically measure. All RAM uses [latching circuitry](https://en.wikipedia.org/wiki/Flip-flop_(electronics) to represent or "store" individual bits. Latches are basically a clever arrangement of transistors, which convert a pulse of electric charge into a constant electric charge. Light switches are examples of latches: To turn an average house light on, you don't have to keep your hand on the switch to keep it on, you flick it "pulse it" high, thus holding or "latching" the light on. The same is true for keeping the light of, you pulse it low and the light stays off.
Turning a bit latch in RAM high stores a 1, which is done by momentarily connecting the "set" pin to a voltage. Storing a 0 is done by momentarily connecting the "reset" pin to a voltage.
So for your gun, say you fire the bullet in the first chamber. To represent that, you reset the first bit in RAM by connecting the latch's reset pin to a high voltage (with something like a push button). Now your RAM looks like this:
011111And as you continue firing...
001111
000111
000011... until you reload, setting every latch again:
1111111
u/Al3ist Dec 31 '23
Ram is the muscles that allow you to pick up heavy objects.
Cpu does brain thingies, like math.
1
Dec 31 '23
You know, Things such as Name, Your Memories are stored in Hard Drive (Permanent)
but things such as ticket number, errands, are like stored in RAM, you may remember those things in whole day but you will forget it the next day or week.
1
u/Fast_Article_5626 Jan 01 '24
it stores all your bullets and everything that's why if u record u gaming and things i recommend 32 or 64 gb of ram
1
u/outragedline Jan 01 '24
ram is a very fast but not reliable storage device, because you can read and write on it at tremendous speeds, but you dont have any warranty that the data will be here after the power suply is cut out
so, imagine that you have a document on excel, the entire document while you are writing is stored on the ram, but when you save it, it write on the disk, where it is reliable to store documents, since on the ram data may be lost (and problably will, by design)
now lets say you want to edit the document again, it will first load all the data to the ram, write there, and only when you save it will be written on the disk
ram is very useful because of its speed, and most programs store just about everything in ram until you do some sort of save, including games
i dont know if its a good explanation but you can ask if theres any questions
1
Jan 01 '24
I have always liked the analogy that RAM is like a desk... A desk holds all the documents and items you need to work on at a given time. RAM allows your computer to quickly access the information it needs to run the programs you're using. When you turn off your computer, the RAM contents are wiped clean, just like when you clear your desk at the end of the day.
1
Jan 01 '24
RAM is volatile so its contents are erased when the system (or application, program, etc.) is terminated. Memory is accessed randomly, so wherever in memory the RAM is accessed, the time is still constant. It's there for quick and temporary memory.
1
u/ihaveseveraljobs Jan 01 '24 edited Jan 01 '24
RAM stores all data used by any running program (games, video editors, text editors, etc). The RAM itself is not responsible for really anything except for being able to store a ‘bit’ (aka a 0 or a 1 at a specific location) and be available for a computer to read or write those bits.
Yes it stores things like:
The number of bullets in a game.
For notepad, it stores each letter in an opened .txt file.
Other pieces of data that the user may not need to be concerned about used in calculations.
Ideally, when a calculation is complete, the piece of RAM that is storing data that is no longer needed is freed up for other calculations. Since a modern PC needs to do a gazillion calculations at once to give you the smooth user experience, a lot of data can be stored in RAM at the same time.
Programmer don't usually need to be concerned with how to talk to the RAM directly, as the OS (Windows, Linux etc) will handle the hardware communication. A programmer will use RAM indirectly when using a programming language:
byte numPlayers = 1; // aka (0x01) aka (0000_0001)
char[] playerName = “Player 1”;In the example above, a programmer is asking for a byte of RAM to store numPlayers, and 8 bytes for playerName (1 byte for each ascii character).
The programmer can change the state of RAM simply by changing the value of a variable in the program:
numPlayer = 255; // aka (0xFF) aka (1111_1111)After running the code above the data stored in RAM that is associated with numPlayers changes from 0x01 to 0xFF. These 0s and 1s represent the state of RAM. And again, the programmer usually doesn’t need to care about how to make the RAM do its job. The programmer can simply do things with the numPlayers variable when writing in a programing language.
As far as video recording, RAM can be useful when buffering a recording. But since the data is usually being written to a file at the same time as the recording, and any data saved to a file is no longer needed in RAM, I don’t think video recording needs a lot of RAM (tech nerds correct me if I’m wrong).
But maybe you might need more RAM if you are doing lengthy recordings, and the computer can't write to a file fast enough to keep up with the recording, so the buffer in RAM starts to grow over time.
Video editing on the other hand is a RAM hog, because video editors will usually want as much of a video in RAM as possible while it is being edited.
1
u/xZniffer Jan 02 '24
Everything you currently use is store in RAM, when you are not using something is usually remove from RAM and maybe available on the storage for future, but most of the usage of RAM is to store the processes flows, these are not on the storage, are for example data created and used along a served process. And now there is cases where we use RAM as a storage itself for faster acces to the data using databases like Redis, but is more to explain.
1
u/DrMrBomb01 Jan 24 '24
I recommend using hex editors or even something like cheat engine for education purposes. As an avid gamer I can relate and the best way how to understand how ram works with your game is to analyze and test how it holds game memory. There are things called memory addresses in your game that the cpu reads and executes. Surprisingly a lot of amateur game hacking is done this way. Modifying the values of memory addresses is the equivalent of changing the value of a variable in code. For example, health, ammo, speed, even coordinates, models, textures, just about everything in the game is stored in the ram.
And you will notice that whenever you restart the game the address changes of a memory address if you have saved it. This is because RAM of a program gets deleted after you exit the process or turn off your computer.
1
0
u/Leverdog882 Dec 30 '23
Computer science student here. Ram is the volatile memory meaning that when power is lost all the data on the ram is cleared aswell. Hence why ram is known as the temporary memory. When you boot up your computer the os from the secondary memory (hardrive) needs to get out onto the ram for the computer to actually run as that’s where your processes are actually running on. So when you open an app the data gets put onto the ram and any processing that happens on that app is being calculated on the ram.
-1
u/acidmole Dec 30 '23
As a rule of thumb, the faster you need it, the closer you have to save it. A game loads a module to RAM to ensure fast calculation (graphic calculations in card's RAM ofc). Even an SSD would be too slow to use as it is around 1000 times slower than fetching it from RAM.
Video editing/recording doesn't probably require that much RAM. The recording itself stores straightly to your hard drive and only the program that handles this recording/editing is loaded into RAM. This is for two reasons: first, calculations needn't to be that fast and second, the recording files are typically too large to fit inside of RAM.
-2
-8
Dec 30 '23
I’m someone who has NO IDEA what he’s talking about.
From what I know, RAM is temporary storage. It’s a pain to pull information out of SSDs, but you can instantly and randomly (means you can pull any information without needing to sort it, I think) pull info out of a RAM.
Basically, RAM is like short-term memory. Pulling info out of and storing it in long-term memory is a pain, so u store it in the short-term memory and throw it away when u no longer need it.
Yeaaaah, if u need alot of things to go on at the same time when ur gaming, get big RAM. Usually tho, 16GB is sufficient. I personally use 8GB for gaming soooo…. Yeah. Many things at same time = big numbers for RAM
2
Dec 30 '23
I think this topic might be more in scope for computer engineering people tho, considering that it involves more hardware
226
u/Kike328 Dec 30 '23
yes, bullets are stored in ram, almost everything is stored in the ram, the 3d models, the weapons, everything, and when you close the program, those things are deleted from the ram.