Most of the people get confused with the terms buffering and caching. Though both holds the data temporarily but, they are different from each other. Buffering is basically used to match the transmission speed between sender and receiver. On the other hands, Cache fastens the access speed of the repeatedly used data. They also share some other differences which have been discussed in the comparison chart below.
Content: Buffering Vs Caching
|Basis for Comparison||Buffering||Caching|
|Basic||Buffering matches the speed between the sender and receiver of the data stream.||Caching fastens the access speed of the repeatedly used data.|
|Stores||Buffer stores the original copy of data.||Cache stores the copy of original data.|
|Location||Buffer is an area in primary memory (RAM).||Cache is implemented on the processor it can be implemeneted on RAM and disk as well.|
Definition of Buffering
Buffering is an area in main memory (RAM) that temporarily stores the data when it is being transferred between two devices, or between a device and application. Buffering helps in matching the speed between the sender and receiver of the data stream. If the sender’s transmission speed is slower than receiver, then a buffer is created in main memory of the receiver, and it accumulates the bytes received from the sender. When all the bytes of the data has arrived then it provides data for the receiver to operate on.
Buffering also helps when sender and receiver have different data transfer size.In computer networking, buffers are used for fragmentation and reassembly of data. At the sender side, the large data is fragmented into small packets and are send over the network. At the receiver side, a buffer is created which collect all the data packets and reassemble them to create a large data again.
Buffering also supports copy semantics for an application I/O. Copy Semantics can be explained with an example, Suppose an application has a buffer of data to be written to the hard disk. For that, the application calls the write() system call. Now suppose application changes the buffer data before system call returns. In this case, copy semantics provide the version of data, at the time of system call.
Buffers are implemented in three capacities.
Zero Capacity: Here the maximum buffer memory size is Zero. It can not contain any data, so the sender must be blocked until the receiver receives the data.
Bounded Capacity: Here the buffer memory size is finite. At max, the sender can send n block of data. If the buffer memory is full, the sender is blocked till space is available in memory.
Unbounded Capacity: here the buffer memory is potentially infinite. Any number of data blocks can be sent. The sender is never blocked.
Definition of Caching
Cache is a memory implemented in the processor that stores the copy of original data. The idea behind caching is that the recently accessed disk blocks must be stored in the cache memory so that when the user again needs to access the same disk blocks, it can be handled locally through cache memory avoiding the network traffic.
Cache size is bounded as it only contains the recently used data. When you modify the cache file, you can view that modification in the original file also. In case the data you require is not in the cache memory, then data is copied from source to the cached memory to make it available to the user when it requests for that data next time.
The cache data can also be kept on disk instead of RAM, as it has one advantage that the disk cache are reliable. In case the system crash the cached data is still available on Disk. But data would be lost in volatile memory like RAM. But one advantage of storing the cached data in RAM is that it would be accessed fast.
Key Differences Between Buffering and Caching in OS
- The key difference between buffer and cache is that buffer memory is used to cope up with the different speed between sender and receiver of the data stream whereas, the cache is a memory which stores the data so that access speed can be fastened for repeatedly used data.
- Buffer always carry the original data to be sent to the receiver. However, cache carries the copy of original data.
- Buffer is always implemented in the main memory (RAM), but, cache can be implemented in RAM as well as in Disk.
Buffering and Caching both stores the data temporarily but both are used for different purpose. Where buffer matches the speed between two communicating devices and the cache fastens the access to data that is repeated visited.