The primary memory of your computer is composed of RAM(Random Access Memory) and ROM(Read Only Memory). At any point, the RAM will hold data and instructions that are currently necessary for running the active programs in the computer system. The ROM will hold special instructions for booting up the computer.
The computer system uses RAM as a fast, general-purpose storage area. We can read and write to it as the computer needs more memory to run current programs. However, this memory is not persistent. Shortly after we power off the computer, the RAM will lose all of the data that is stored within it. On the other hand, ROM can’t be overwritten but it has non-volative memory, which means it doesn’t lose its contents if power is lost.
Increasing the RAM to your system will potentially allow it to run more programs or more memory intensive tasks. However, RAM can become “full” in which case we will need to use the next layer of storage, most likely the Secondary memory, which we will talk more about next section.
There are different types of RAM:
If you’d like to know the specifics of each one you can look at this great article.
Generally speaking, DRAM is cheaper but slower so it is used as the main RAM for a computer system. SRAM is faster but more expensive, so it is used in smaller amounts as cache memory. The most actively used information is placed in the SRAM which means that the computer system will have faster access to it. If the data that the computer needs is not in the data, it is fetched from DRAM and copied into the cache, and then used. If the CPU needs to write to memory, it does so through the cache as well.
Within our kitchen analogy we have a counter with registers, which are the instructions and data that the chef is currently using. Once we need new data we would then go to primary memory, which would be the fridge or the pantry. Instead of going to the main fridge we could also have smaller, more expensive fridges that come out of the ground we are standing in. This would make accessing our data much faster, but it would definitely take some time to build these caches and it would cost a lot of money so we can’t just have a huge cache come out of the ground.
To add to the complexity there are different levels of cache, L1, L2, L3 etc. L1 is placed on the microprocessor itself whereas L2 is placed a bit further, between the rest of the RAM memory and the microprocessor.