Cache memory is a small and fast memory which is placed between the CPU and RAM. It is accessed at a very high speed than the system memory. As a result, the programs which access the same data or instructions over and over run faster. The CPU does not have traverse to the main memory to get the data. It will first access the cache to find the data.
CPU does a check on the cache to find the data, if it does not check then it proceeds to the system memory. This results in faster access to the data in the cache. But, it will be lagging if the data is not in the cache and on the system memory. This can be countered with modern hardware and better cache design. The time taken to traverse the cache is very less as compared to the whole RAM as it is small and fast memory.
The write through type of cache memory makes the data go through the cache to the main memory. Once the data is written to the main memory then only the processor can continue with the next operation. Processor has to wait till the cache memory updates the main memory.
When some data is written to this type of cache, the cache accepts the data and informs the processor that the data is written. Afterwards this data is written back to the main memory by the cache whenever it finds some free time.
The effectiveness of cache memory depends on mapping of cache memory to the system memory. The user can allocate storage in cache memory to the memory addresses in different ways. The different types of cache mapping techniques are:
• Direct Mapped Cache - Maps one memory address of the system memory to one area in the cache. This also degrades the performance of the cache, since only that many memory addresses can be stored in the cache.
• Fully Associative Cache - Stores memory location of the system memory at any position in the cache. This results in a better cache hit ratio. But results in slow access time as the search has to be done on all positions in the cache to find the required data.
• N-Way Set Associative Cache - Stores one memory address of the system memory at most four places in the cache. It is the best middle way between the above two methods. It requires to have specialized hardware to search for the data in the cache.
You may also be interested in
Types of memory packages