buffer:
In computing, a buffer is a region of memory used to temporarily hold data while it is being moved from one place to another. Typically, the data is stored in a buffer as it is retrieved from an input device (such as a keyboard) or just before it is sent to an output device (such as a printer). However, a buffer may be used when moving data between processes within a computer. This is comparable to buffers in telecommunication. Buffers can be implemented in either hardware or software, but the vast majority of buffers are implemented in software. Buffers are typically used when there is a difference between the rate at which data is received and the rate at which it can be processed, or in the case that these rates are variable, for example in a printer spooler.
cache:
In computer science, a cache (pronounced /ˈkæʃ/, like "cash" [1]) is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (owing to longer access time) or to compute, compared to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, future use can be made by accessing the cached copy rather than re-fetching or recomputing the original data, so that the average access time is shorter. Cache, therefore, helps expedite data access that the CPU would otherwise need to fetch from main memory.
也就是说当你把数据写入目标设备时,需要考虑这个设备的单位时间内的数据接受能力和处理能力, 如果接受能力大于处理能力的话, 就有必要加个buffer来缓冲下.
cache是用来临时存放经常需要读取的数据的地方, 它的访问速度通常要快于保存这些数据的设备, 所以把这些数据预读到cache里能提高访问速度.
其实buffer和cache有时候也是结合在一起用的, 比如数据库的buffer pool, 这里面的数据最终是要被写到数据文件里面,从这方面说它是buffer.这个里面的数据也可以被其他的进程访问, 以提升读取速度, 从这方面看又有cache的应用了.
|