tags:

views:

996

answers:

7

I see word BUFFER everywhere but I am unable to grasp what it exactly is.

  1. Would anybody please explain what is buffer in layman's language?
  2. When is it used?
  3. How is it used?

Thanks.

+9  A: 

The term "buffer" is a very generic term, and is not specific to IT or CS. It's a place to store something temporarily, in order to mitigate differences between input speed and output speed. While the producer is being faster than the consumer, the producer can continue to store output in the buffer. When the consumer speeds up, it can read from the buffer. The buffer is there in the middle to bridge the gap.


If you average out the definitions at http://en.wiktionary.org/wiki/buffer, I think you'll get the idea.

For proof that we really did "have to walk 10 miles thought the snow every day to go to school", see http://www.bitsavers.org/pdf/dec/pdp10/TOPS10_softwareNotebooks/vol04/AA-0974G-TB_monCallsVol1.pdf, section 11.9, "Using Buffered I/O", at bookmark 11-24. Don't read if you're subject to nightmares.

John Saunders
+1 I like this explanation better. As much as I love candy, the candy bowl example was a bit of a stretch IMO.
Outlaw Programmer
Yes, "a place to store something temporarily, in order to mitigate differences between input speed and output speed" sums it up perfectly.
chimp
+18  A: 

Imagine that you're eating candy out of a bowl. You take one piece regularly. To prevent the bowl from running out, someone might refill the bowl before it gets empty, so that when you want to take another piece, there's candy in the bowl.

The bowl acts as a buffer between you and the candy bag.

If you're watching a movie online, the web service will continually download the next 5 minutes or so into a buffer, that way your computer doesn't have to download the movie as you're watching it (which would cause hanging).

Perchik
+1: Buffers are required when producers and consumers operate at different rates. Candy is made in large batches but consumed in smaller quantities -- the entire supply chain from manufacturer to mouth is a series of buffers.
S.Lott
A: 

Buffer is temporary placeholder (variables in many programming languages) in memory (ram/disk) on which data can be dumped and then processing can be done.

There are many advantages of Buffering like it allows things to happen in parallel,improve IO performance,etc.

It also has many downside if not used correctly like buffer overflow,buffer underflow,etc.

C Example of Character buffer.

char *buffer1 = (char *)calloc(5, sizeof(char));

char *buffer2 = (char *)calloc(15, sizeof(char));

+2  A: 

Really it would depend on the context in each case as there is no one definition - but speaking very generally a buffer is an place to temporarily hold something. The best real world analogy I can think of would be a waiting area. One simple example in computing is when buffer refers to a part of RAM used for temporary storage of data.

Fraser
+1  A: 

A buffer is simply a chunk of memory used to holding data. In the most general sense, it's usually a single blob of memory that's loaded in one operation, and then emptied in one or more, Perchik's "candy bowl" example. In a C program, for example, you might have:

#define BUFSIZE 1024
char buffer[BUFSIZE];
ssize_t len = ;

// ... later
while((len=read(STDIN, &buffer, BUFSIZE)) > 0)
    write(STDOUT, buffer, len);

... which is a minimal version of cp(1). Here, the buffer array is used to store the data read by read(2) until it's written; then the buffer is re-used.

There are more complicated buffer schemes used, for example a circular buffer, where some finite number of buffers are used, one after the next; once the buffers are all full, the index "wraps around" so that the first one is re-used.

Charlie Martin
A: 

Buffer means 'temporary storage'. Buffers are important in computing because interconnected devices and systems are seldom 'in sync' with one another, so when information is sent from one system to another, it has somewhere to wait until the recipient system is ready.

karim79
A: 

Buffer is temporary placeholder (variables in many programming languages) in memory (ram/disk) on which data can be dumped and then processing can be done.

The term "buffer" is a very generic term, and is not specific to IT or CS. It's a place to store something temporarily, in order to mitigate differences between input speed and output speed. While the producer is being faster than the consumer, the producer can continue to store output in the buffer. When the consumer speeds up, it can read from the buffer. The buffer is there in the middle to bridge the gap.