Memory of a computer is organized in to a hierarchy and they are organized considering the time taken to access them, cost and capacity. RAM and cache memory are two members in this memory hierarchy. RAM (Random Access Memory) is the primary memory used in a computer. Its individual memory cells can be accessed in any sequence, and therefore it is called the random access memory. RAMs are divided in to two categories as Static RAM (SRAM) and Dynamic RAM (DRAM). Cache memory is a special memory used by the CPU (Central Processing Unit) of a computer for the purpose of decreasing the average time required to access memory.
What is RAM?
RAM is also known as the main memory of a computer. It is a volatile memory in which the data that is stored in the memory is lost when the power is turned off. RAMs are divided in to two categories as Static RAM (SRAM) and Dynamic RAM (DRAM). SRAM uses transistors to store a single bit of data and it does not need to be periodically refreshed. DRAM uses a separate capacitor to store each bit of data and it needs to be periodically refreshed to maintain the charge in the capacitors. In modern computers, RAM is organized in to modules that can be upgraded. This would allow increasing the RAM capacity or fixing damages very easily.
What is Cache Memory?
Cache memory is a special memory used by the CPU for the purpose of decreasing the average time taken for memory accesses. Cache memory is relatively a smaller and also a faster memory, which stores most frequently accessed data of the main memory. When there is request for a memory read, cache memory is checked to see whether that data exists in cache memory. If that data is in the cache memory, then there is no need to access the main memory (which takes longer time to be accessed), therefore making the average memory access time smaller. Typically, there are separate caches for data and instructions. Data cache is typically set up in a hierarchy of cache levels (sometimes called multilevel caches). L1 (Level 1) and L2 (Level 2) are the top most caches in this hierarchy of caches. L1 is the closest cache to the main memory and is the cache that is checked first. L2 cache is the next in line and is the second closest to main memory. L1 and L2 vary in access speeds, location, size and cost.
What is the difference between RAM and Cache Memory?
In the memory hierarchy, cache memory is the closer memory to the CPU when compared with the RAM. Cache memory is much faster and also expensive when compared with the RAM. But the capacity of the RAM memory is larger than the capacity of the cache memory. Further, the cache memory is also organized as a hierarchy as L1, L2 and L3 caches that differ in speed, cost and capacity.