cache和buffer的区别

A buffer is just a container to hold data for a short period of time when more comes in at any given time than a consumer can use / process. It's a first-in, first-out situation - the data comes in, might be buffered, and goes out in the same order it came in, after a while.

A cache is a storage for speeding up certain operations. Things get put in a cache, and should be retrieved from it multiple times, over and over again. There's no "flowing through the cache" kind of mechanism - data doesn't come in and go out in the same order - but it's just a holding container. The order might be anything, really - items are addressed via a key, they don't "flow through" but they are "put in" and stay there (until they're thrown out because of not being used, or because the system goes down).

 

buffer中的数据是一次性的,主要是处理数据的速度不如数据到达的速度,当然也有其他原因(例如标准输入输出中的buffer则考虑的是减少系统调用)

cache则是一种需要软件和硬件配合实现的机制,用于加快数据处理速度。

总结一下:cache主要是存放最频繁访问的数据(例如根据程序的局部性原理,使用最近最少使用算法淘汰),buffer则主要考虑的是设备间的传输速度差距。

 

 

posted @ 2014-02-10 14:34  johnny_HITWH  阅读(343)  评论(0编辑  收藏  举报