What does it mean by buffer?
Asked Answered
T

9

239

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?
Thomasinathomasine answered 15/3, 2009 at 18:43 Comment(1)
I've noticed that "buffer" has slight variations in name, and they tend to change based on exactly what physical memory is holding it and for what. Like "Graphics buffer" is a char array for video memory, while Network Buffer may be in the normal RAM. I'm unsure if this is standard or happenstance. Similar to Ailayna's answer towards the end.Exorbitance
T
453

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

Topaz answered 15/3, 2009 at 18:50 Comment(5)
+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.Stature
Best analogy ever. Makes me crave sugarPseudonymous
what's the web service here? Where's the buffer? Is the web service the movie host?Folliculin
Solid definition. I guess that's why we say the video is buffering when it freezes, and progress bar is showing when we are watching a movieWigwag
This is so nice, feasible and simple.Motch
T
138

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.

Toms answered 15/3, 2009 at 18:46 Comment(5)
+1 I like this explanation better. As much as I love candy, the candy bowl example was a bit of a stretch IMO.Sonorant
Yes, "a place to store something temporarily, in order to mitigate differences between input speed and output speed" sums it up perfectly.Tremendous
thank you for the simple explanation. However, the attached PDF url has been deadSanguinolent
When the consumer speeds up, it can read from the buffer. I'm having hard time understanding this line. Does it really wait for consumer to speed up before it can start reading from buffer? Wouldn't it just start reading once the buffer is full no matter the speed?Sheriesherif
@V_S_X I edited my answer to make it clear that the consumer doesn't actually need to speed up. In fact, the consumer can continue to be slow, or slower, until the buffer fills. But also, the consumer doesn't wait for the buffer to be full before reading. It just reads, as fast as it wants to read it. If the difference between the consumer and producer speed is too great, then the buffer could overflow.Toms
B
31

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.

Booma answered 15/3, 2009 at 18:58 Comment(0)
D
24

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.

Deform answered 15/3, 2009 at 19:22 Comment(0)
L
8

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.

Lioness answered 15/3, 2009 at 18:57 Comment(0)
M
4

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.

Maple answered 20/3, 2022 at 13:42 Comment(0)
P
3

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.

Professional answered 11/10, 2014 at 4:51 Comment(0)
M
2

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));
Mallarme answered 15/3, 2009 at 18:53 Comment(0)
P
2

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.

Paramatta answered 10/6, 2009 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.