Memory is needed to store data and retrieve it when needed. Computers have two kind of memory, one is primary and another is secondary.
Secondary memory is commonly known as just storage. It's used to store files when they are not needed by the processors. The examples are HDD, SSD, USB Drives, SD Cards etc.
Primary memory is needed to execute any program. Your program when executed loads itself into primary memory. When program runs, it needs to work on variables, objects, data structure etc. to store data. For example if it needs to store value 10, it'll need an integer datatype while for storing text, it'll need a string data type. These data types stores these values into primary memory. Apart from that some programs needs to access files which are also gets loaded into primary memory for execution and then after releasing them, they go back with changes (if any) to secondary memory.
Primary memory example could be RAM, ROM, L1 & L2 Cache, Registers etc. Processor works as a primary memory too since they have limited storage too.
Now the question is why do we need Primary memory like RAM at all? Can't we just use Secondary memory for this?
We can, in fact we do. When RAM ran out of space to open new files, the OS uses Hard disks as primary memory by creating page files on that. If you have seen pageswap or page files in your system's hidden files then you have seen the proof.
Now why do we need it? We need processors to run the commands, however processors are really costly and they can not hold much data in them. Processors are really fast, but we need to store the data processors are not currently using, even in the running program. Caches are faster kind of memory which can be used by Processors very easily. However they are costly too (L1 is faster and costly than L2). Registers are next faster memory and RAM is the next fastest and the cheapest option.
RAMs can't hold the data, so we need a persistent data storage such as HDDs. HDD works on magnetic resonance principles and are really slow. However they are faster than Optical disks such as CDs and DVDs. SSDs are faster, but they still can't compete with RAMs. RAMs are electronic drives which can connect with Processors with ease.
Consider an example of slow moving traffic. If the fastest car is behind slow moving cars, it will move as fast as the slowest car in the lane. That's why the slowness of HDDs affect the Processors' execution speed. Thus we need RAM for this.
No comments:
Post a Comment