What does it mean by buffer?

BufferTerminology

Buffer Problem Overview


I see the 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?

Buffer Solutions


Solution 1 - Buffer

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).

Solution 2 - Buffer

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 gets around to it, 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 TOPS-10 Monitor Calls Manual Volume 1, section 11.9, "Using Buffered I/O", at bookmark 11-24. Don't read if you're subject to nightmares.

Solution 3 - Buffer

A buffer is simply a chunk of memory used to hold 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];
size_t len = 0;

// ... 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.

Solution 4 - Buffer

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.

Solution 5 - Buffer

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.

Solution 6 - Buffer

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 = calloc(5, sizeof(char));

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

Solution 7 - Buffer

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.

Solution 8 - Buffer

A buffer is a data area shared by hardware devices or program processes that operate at different speeds or with different sets of priorities. The buffer allows each device or process to operate without being held up by the other. In order for a buffer to be effective, the size of the buffer and the algorithms for moving data into and out of the buffer.

buffer is a "midpoint holding place" but exists not so much to accelerate the speed of an activity as to support the coordination of separate activities.

This term is used both in programming and in hardware. In programming, buffering sometimes implies the need to screen data from its final intended place so that it can be edited or otherwise processed before being moved to a regular file or database.

Solution 9 - Buffer

That a buffer is "a place to store something temporarily, in order to mitigate differences between input speed and output speed" is accurate, consider this as an even more "layman's" way of understanding it.

"To Buffer", the verb, has made its way into every day vocabulary. For example, when an Internet connection is slow and a Netflix video is interrupted, we even hear our parents say stuff like, "Give it time to buffer."

What they are saying is, "Hit pause; allow time for more of the video to download into memory; and then we can watch it without it stopping or skipping."

Given the producer / consumer analogy, Netflix is producing the video. The viewer is consuming it (watching it). A space on your computer where extra downloaded video data is temporarily stored is the buffer.

A video progress bar is probably the best visual example of this:

Video progress bar with grey buffered video content

That video is 5:05. Its total play time is represented by the white portion of the bar (which would be solid white if you had not started watching it yet.)

As represented by the purple, I've actually consumed (watched) 10 seconds of the video.

The grey portion of the bar is the buffer. This is the video data that that is currently downloaded into memory, the buffer, and is available to you locally. In other words, even if your Internet connection where to be interrupted, you could still watch the area you have buffered.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPratik DeoghareView Question on Stackoverflow
Solution 1 - BufferPerchikView Answer on Stackoverflow
Solution 2 - BufferJohn SaundersView Answer on Stackoverflow
Solution 3 - BufferCharlie MartinView Answer on Stackoverflow
Solution 4 - Bufferkarim79View Answer on Stackoverflow
Solution 5 - BufferFraserView Answer on Stackoverflow
Solution 6 - BufferSantosh GokakView Answer on Stackoverflow
Solution 7 - BufferSanjeevView Answer on Stackoverflow
Solution 8 - BufferAilayna EntarriaView Answer on Stackoverflow
Solution 9 - Bufferuser658182View Answer on Stackoverflow