在C语言中,stdout缓冲区的大小是多少? [英] In C, what's the size of stdout buffer?

查看:658
本文介绍了在C语言中,stdout缓冲区的大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我了解到,将stdout设置为terminal时,stdout是行缓冲的,并在不同情况下进行缓冲.因此,在正常情况下,如果我使用printf()而不以"\ n"结尾,则仅在缓冲区已满时才将其打印在屏幕上.如何获得此缓冲区的大小,这有多大?

Today I learned that stdout is line buffered when it's set to terminal and buffered in different cases. So, in normal situation, if I use printf() without the terminating '\n' it will be printed on the screen only when the buffer will be full. How to get a size of this buffer, how big is this?

推荐答案

实际大小由各个实现定义;该标准并没有规定最小大小(无论如何,基于我所能找到的大小).没有关于如何确定缓冲区大小的线索.

The actual size is defined by the individual implementation; the standard doesn't mandate a minimum size (based on what I've been able to find, anyway). Don't have a clue on how you'd determine the size of the buffer.

修改

章节和经文:

7.19.3文件

...
3当流是 unbuffered 时,字符应显示在源中或在 尽快到达目的地.否则可能会累积字符,并且 传输到主机环境或从主机环境传输出去.当流完全缓冲时, 字符打算在以下情况下作为块与主机环境进行传输: 缓冲区已填满.当流被行缓冲时,字符应为 当换行符是 遭遇.此外,打算将字符作为一个块发送到主机 缓冲区已填充,在未缓冲的流上请求输入时的环境,或 当在需要传输以下内容的行缓冲流上请求输入时 主机环境中的字符. 对这些特征的支持是 实现定义的内容,可能会受到setbufsetvbuf函数的影响.

7.19.3 Files

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

添加了重点.

实现定义"不是对我不知道"的委婉说法,它仅是语言标准明确地将其留给实现进行定义的声明. em>行为.

"Implementation-defined" is not a euphemism for "I don't know", it's simply a statement that the language standard explicitly leaves it up to the implementation to define the behavior.

而且,有 种非编程方式可以找到答案;请查阅您的编译器的文档. 实施定义"还意味着实施必须记录行为:

And having said that, there is a non-programmatic way to find out; consult the documentation for your compiler. "Implementation-defined" also means that the implementation must document the behavior:

3.4.1

1 实施定义的行为
未指明的行为,其中每个实现都记录了如何做出选择

2示例实现定义的行为的一个示例是高阶位的传播 当有符号整数右移时.

3.4.1

1 implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made

2 EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit when a signed integer is shifted right.

这篇关于在C语言中,stdout缓冲区的大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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