在C中,完全缓冲,行缓冲和非缓冲是什么意思? [英] What do fully buffered, line buffered and unbuffered mean in C?

查看:121
本文介绍了在C中,完全缓冲,行缓冲和非缓冲是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到一条线,该行从cat命令的输出被完全缓冲.是什么意思?

I came across a line that output from cat command is fully buffered. What does it mean?

推荐答案

在线C11标准,7.21.3/3:

Online C11 standard, 7.21.3/3:

当流没有缓冲 时,字符应尽快从源或目标位置出现.否则,字符可能会作为块被累积并传输到主机环境或从主机环境传输.当完全缓冲流时,打算在填充缓冲区时将字符作为块与主机环境进行传输.当流被行缓冲时,当遇到换行符时,字符将作为块与主机环境进行传输.此外,当填充缓冲区,在无缓冲流上请求输入或在需要从主机环境传输字符的行缓冲流上请求输入时,打算将字符作为块传输到主机环境. .对这些特性的支持是实现定义的,并且可能会受setbufsetvbuf函数的影响.

When a stream is unbuffered, characters are intended to appear from the source or at the destination as soon as possible. Otherwise characters may be accumulated and transmitted to or from the host environment as a block. When a stream is fully buffered, characters are intended to be transmitted to or from the host environment as a block when a buffer is filled. When a stream is line buffered, characters are intended to be transmitted to or from the host environment as a block when a new-line character is encountered. Furthermore, characters are intended to be transmitted as a block to the host environment when a buffer is filled, when input is requested on an unbuffered stream, or when input is requested on a line buffered stream that requires the transmission of characters from the host environment. Support for these characteristics is implementation-defined, and may be affected via the setbuf and setvbuf functions.

7.21.3/7:

在程序启动时,预定义了三个文本流,无需显式打开它们-标准输入(用于读取常规输入),标准输出(用于写入常规输出)和标准错误(用于写入诊断输出).最初打开时,标准错误流未完全缓冲;仅当可以确定标准输入和标准输出流不引用交互式设备时,标准输入流和标准输出流才被完全缓冲.

At program startup, three text streams are predefined and need not be opened explicitly — standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). As initially opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device.

这篇关于在C中,完全缓冲,行缓冲和非缓冲是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆