缓冲区是什么意思?

发布于 2024-07-14 15:25:49 字数 139 浏览 9 评论 0原文

我到处都看到“BUFFER”这个词,但我无法理解它到底是什么。

  1. 有人可以用外行语言解释一下什么是缓冲区吗?
  2. 什么时候使用?
  3. 它是如何使用的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

叹倦 2024-07-21 15:25:49

想象一下你正在吃碗里的糖果。 您定期服用一件。 为了防止碗用完,有人可能会在碗空之前重新装满,这样当你想再拿一块时,碗里就有糖果了。

碗充当您和糖果袋之间的缓冲区。

如果您正在在线观看电影,网络服务将不断地将接下来的 5 分钟左右下载到缓冲区中,这样您的计算机就不必在您观看时下载电影(这会导致挂起)。

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

甜心 2024-07-21 15:25:49

术语“缓冲区”是一个非常通用的术语,并非 IT 或 CS 特有的。 它是临时存储某些内容的地方,以减轻输入速度和输出速度之间的差异。 当生产者比消费者更快时,生产者可以继续将输出存储在缓冲区中。 当消费者有时间时,它可以从缓冲区中读取。 缓冲区位于中间以弥补间隙。


如果您对 http://en.wiktionary.org/wiki/buffer 中的定义进行平均,我想你会明白的。

要证明我们确实“每天都在下雪的情况下步行 10 英里才能上学”,请参阅 TOPS-10 监视器调用手册第 1 卷,第 11.9 节,“使用缓冲 I/O”,书签 11-24。 如果您经常做噩梦,请不要阅读。

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.

愿与i 2024-07-21 15:25:49

缓冲区只是用于保存数据的一块内存。 从最一般的意义上来说,它通常是在一个操作中加载的单个内存块,然后在一个或多个操作中清空,如 Perchik 的“糖果碗”示例。 例如,在 C 程序中,您可能有:

#define BUFSIZE 1024
char buffer[BUFSIZE];
size_t len = 0;

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

... 这是 cp(1) 的最小版本。 这里,缓冲区数组用于存储read(2)读取的数据,直到写入; 然后缓冲区被重新使用。

还使用了更复杂的缓冲区方案,例如循环缓冲区,其中使用了一些有限数量的缓冲区,一个接着一个; 一旦缓冲区全部填满,索引就会“回绕”,以便重新使用第一个缓冲区。

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.

夜深人未静 2024-07-21 15:25:49

缓冲区的意思是“临时存储”。 缓冲区在计算中很重要,因为互连的设备和系统很少彼此“同步”,因此当信息从一个系统发送到另一个系统时,它会在某个地方等待,直到接收系统准备好。

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.

寂寞美少年 2024-07-21 15:25:49

实际上,这取决于每种情况的上下文,因为没有一个定义 - 但一般来说,缓冲区是临时保存某些东西的地方。 我能想到的最好的现实世界比喻就是等候区。 计算中一个简单的例子是缓冲区指的是 RAM 中用于临时存储数据的一部分。

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.

柒夜笙歌凉 2024-07-21 15:25:49

缓冲区是“临时存储某些内容的地方,以减轻输入速度和输出速度之间的差异”是准确的,请将此视为更“外行”的理解方式。

“To Buffer”这个动词已经进入了日常词汇中。 例如,当互联网连接速度缓慢且 Netflix 视频中断时,我们甚至会听到父母说“给它时间缓冲”之类的话。

他们的意思是,“暂停;留出时间让更多视频下载到内存中;然后我们就可以在不停止或跳过的情况下观看它。”

考虑到制作者/消费者的类比,Netflix 正在制作视频。 观众正在消费它(观看它)。 计算机上临时存储额外下载的视频数据的空间就是缓冲区。

视频进度条可能是最好的视觉示例:

带有灰色缓冲视频内容的视频进度条

该视频为 5:05。 它的总播放时间由条形的白色部分表示(如果您还没有开始观看,则该部分将是纯白色。)

如紫色所示,我实际上已经消耗了(观看过)视频10秒。

条形的灰色部分是缓冲区。 这是当前下载到内存、缓冲区中的视频数据,您可以在本地使用。 换句话说,即使您的互联网连接中断,您仍然可以观看已缓冲的区域。

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.

半世蒼涼 2024-07-21 15:25:49

缓冲区是由以不同速度或不同优先级运行的硬件设备或程序进程共享的数据区域。 缓冲区允许每个设备或进程在不被其他设备或进程阻碍的情况下运行。 为了使缓冲区有效,缓冲区的大小以及将数据移入和移出缓冲区的算法。

缓冲区是一个“中点保持位置”,但其存在并不是为了加快活动的速度,而是为了支持单独活动的协调。

该术语用于编程和硬件中。 在编程中,缓冲有时意味着需要从最终预期位置筛选数据,以便在将其移动到常规文件或数据库之前可以对其进行编辑或以其他方式处理。

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.

待"谢繁草 2024-07-21 15:25:49

缓冲区是内存(RAM/磁盘)中的临时占位符(许多编程语言中的变量),可以在其中转储数据然后进行处理。

术语“缓冲区”是一个非常通用的术语,并非 IT 或 CS 特有的。 它是临时存储某些内容的地方,以减轻输入速度和输出速度之间的差异。 当生产者比消费者更快时,生产者可以继续将输出存储在缓冲区中。 当消费者加速时,它可以从缓冲区中读取。 缓冲区位于中间以弥补间隙。

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.

懒猫 2024-07-21 15:25:49

缓冲区是内存(RAM/磁盘)中的临时占位符(许多编程语言中的变量),可以在其中转储数据然后进行处理。

缓冲有很多优点,例如它允许并行发生、提高 IO 性能等。

如果使用不当,它也有许多缺点,例如缓冲区溢出、缓冲区下溢等。

字符缓冲区的 C 示例。

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

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

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文