What is Buffer Memory?
We know that speed of a processor is much higher than the speed of its attached input-output peripherals. So, most of processor time is wasted being ideal while waiting for the IO peripherals to respond. To utilize the processor time properly we use buffer memory. A buffer is a temporary storage region, typically in RAM. The idea of the buffer was employed to prevent data congestion from an incoming port to an outgoing port of transfer. Most of the buffers are used for holding data to be forwarded to I/O devices and in the meantime CPU keeps on processing other requests or processes. Since the processes of reading and writing data to a disk are comparatively slow, many programs track the data changes in a buffer and then this buffer data is copied to a disk.
Also read – Types of Computer Memory
Now, let us consider some examples where we see buffer memory being used.
- As an example, consider word processors which employ a buffer to trace all changes made to files and on saving the file the word processor updates the disk file contents by copying the contents of the buffer memory. This is more efficient method to manage changes than accessing the file on the disk each time. But it should be noted that initially the changes are made and temporarily stored in buffer memory and not on the disk, so if the computer fails while we are editing file then we will lose the content of the file. So it is important to save your file at regular intervals of time. With new features most of the word processors auto-save the file contents periodically.
- Keyboard drivers also have a buffer to enable us to edit typing mistakes in command before sending them to a program.
- Another use of buffers is for printing files or documents. When a print command is given the processor copies the file contents to a print buffer (which is free space in memory or on a disk called as spool) and the printer then can use buffer data at its own speed to print the same. Thus, printer keeps on working in background.
- When we have to copy a file to floppy disk or burn data on a compact disk, buffers are usually used. Here data is transferred to buffers before being copied to floppy disk or before writing it to the disc.
- DOS and other operating systems, also have a disk buffer to hold data read from disk temporarily.
- when we want to watch or download an online video or audio file, a specific percentage of the downloaded file is put in the buffer. Then the file is played and the device constantly downloads the file and places it in the buffer. So, very less chances that the video or audio file will interrupt due to network congestion.
Also read – What is Virtual Memory?
What is a Cache?
Cache in computer science is defined as hardware or software which is used to hold data, temporarily. Cache is a high speed and expensive memory which can be a part of main memory or hard disk. Cache is used to improve the performance of a computer. To do so data or files which have been accessed or used frequently are stored temporarily in cache. We need cache because bulk memories such as RAM or hard disk have slow speed and cannot upkeep with demands of high speed clients such as the CPU, operating systems, applications or web browsers. Thus, cache reduces the data access time and latency time thus improving the performance of I/O.
Difference between Buffer Memory and Cache
Both buffer memory and cache are memory spaces used to store data temporarily but there are many differences between them, such as:
|Buffer Memory||Cache Memory|
|The buffer memory is mainly located in Random Access Memory (RAM) of a computer.||It is part of either main memory or hard disk|
|In this area CPU can store its data temporarily, like the data to be forwarded to other slow speed output devices or other secondary storage devices, to enable the computer to execute other processes.||Information that is used and accessed by most of the programs while running is stored in cache to make them faster.|
|It is normal storage area in dynamic RAM||It is high speed storage area of static RAM.|
|The buffer is normally used for input/output processes for sending or receiving data, for example, input from keyboard or output to printer.||Cache is used to store data or files temporarily that are accessed frequently by processes|
|It stores or holds the actual copy of data.||Cache holds the copy of original data.|
|It is implemented to match the speed of slow IO devices with processor.||It is implemented to reduce the access time and improve the latency time of frequently used data.|
Both buffer memory and cache are memory spaces that are used to store data temporarily buffer being part of RAM and specifically dynamic RAM whereas cache is a high speed memory which can be part of RAM (Static RAM) or hard disk and both buffer and cache have become the integral part of a computer system. Both of them aid in improving the speed of operations of the CPU. Think for a while what will happen if there is no buffer memory and cache?