Chinaunix首页 | 论坛 | 博客
  • 博客访问: 841248
  • 博文数量: 116
  • 博客积分: 1472
  • 博客等级: 上尉
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-06 11:45
文章分类

全部博文(116)

文章存档

2015年(1)

2014年(42)

2013年(5)

2012年(19)

2011年(49)

我的朋友

分类: 嵌入式

2014-02-08 07:48:12


Key difference: A cache transparently stores data so that future requests for that data can be served faster. A buffer, on the other hand, temporarily stores data while the data is the process of moving from one place to another.

 


 

There are two main types of caches, memory caching and disk caching. Memory caching is when the cache is part of the main memory, whereas disk caching is when the cache is part of some other separate storage area, such as a hard disk. Caching is the process of storing data in a cache so that the data can be accessed faster in the future. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere. When some data is requested, the cache is first checked to see whether it contains that data. The data can be retrieved more quickly from the cache than from its source origin.

 

An easy example to understand caching is to look at web caching. A web cache is a mechanism for the temporary storage (caching) of web documents, such as HTML pages and images. This is mainly done to reduce bandwidth usage, server load, and perceived lag. When a web page is loaded, the data on the pages is cached; hence the next time the page is loaded it is quicker, as data is already present, and only the changes made to the page need to be loaded, which are in turn cached for next time. Google's cache link in its search results provides a way of retrieving information from websites that have recently gone down and a way of retrieving data more quickly than by clicking the direct link.

 

The buffer, on the other hand, is found mainly in the RAM and acts as an area where the CPU can store data temporarily. This area is used mainly when the computer and the other devices have different processing speeds. Typically, the data is stored in a buffer as it is retrieved from an input device (such as a mouse) or just before it is sent to an output device (such as speakers). However, the buffer may also be used when moving data between processes within a computer.

 

So, the computer writes the data up into a buffer, from where the device can access the data, as its own speed. This allows the computer to be able to focus on other matters after it writes up the data in the buffer; as oppose to constantly focus on the data, until the device is done.

 

Buffers can be implemented in a fixed memory location in hardware or by using a virtual data buffer in software, which points to a data buffer are stored on a physical storage medium. Majority of the buffers are utilized in the software. These buffers typically use the faster RAM to store temporary data, as RAM has a much faster access time than hard disk drives. A buffer often adjusts timing by implementing a queue or FIFO algorithm in memory. Hence, it is often writing data into the queue at one rate and reading it at another rate.

 

http://www.differencebetween.info/sites/default/files/images/buffering.jpgA common example of this is streaming videos online, such as YouTube. While, watching a video on YouTube, one may notice that a gray bar tends to load before the red bar of the video stream can play. The gray bar is the buffer. It downloads the data of the video and saves it so that the video may play at an uninterrupted rate. As you might have noticed that when the red bar catches up to the gray bar, the video stops, in order to load the rest of the video.

 

Buffers are also often used with I/O to hardware, such as disk drives, sending or receiving data to or from a network, or playing sound on a speaker. Buffers are used for many purposes, such as interconnecting two digital circuits operating at different rates, holding data for use at a later time, allowing timing corrections to be made on a data stream, collecting binary data bits into groups that can then be operated on as a unit, and delaying the transit time of a signal in order to allow other operations to occur.

 

However, a buffer cannot be used to instantaneously move your location in the data stream, unless the new part has already been moved to the buffer. Similar to the YouTube video, which cannot be forwarded to a part that is not covered by the gray bar.  If you do, the buffer will relocate and restart from the new location.

 

Still, the functions of a cache and buffer are not mutually exclusive and are often combined for an ideal performance. 

 

阅读(674) | 评论(0) | 转发(0) |
0

上一篇:cpio格式 initrd 的解压与压缩

下一篇:Cache

给主人留下些什么吧!~~