This article understands caching and buffering, what exactly do chche and buffer do?

1. Buffer

(1) Definition

The buffer is a memory area used to store data transferred between two devices or between a device and an application .

(2) The purpose of setting the buffer or the function of the buffer is

① The first function is to deal with the speed difference between producers and consumers of data streams .
②Secondly, it is to coordinate the devices with inconsistent transmission data size .
Another role is to support the application's copy semantics .
The so-called copy semantics is understood as follows: If you want to write the data in the memory to the disk, use the write() system call. According to the copy semantics, the data that needs to be written is the version when the write() system call is issued, and then the buffer of the program No need to worry about changes. At this time, the kernel buffer will come in handy to store the required version of the data.

2. Cache cache

(1) Definition

The cache is a high-speed memory that can store a copy of the data. The access to the data in the cache area is more efficient than the access to the original data .

3. The difference between the two

The difference between buffer and cache is that the buffer may hold the only copy of the data, and by definition the cache only provides a copy of the data residing in other places on the high-speed storage , and there may be multiple copies for access Efficient.

Another point is that the cache and the buffer can be the same memory area .

Guess you like

Origin blog.csdn.net/weixin_44142774/article/details/114629492