最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

apue在線版本 unix編程環(huán)境online

2022-01-26 19:49 作者:信號(hào)再生中  | 我要投稿

https://notes.shichao.io/apue/ch5/

Buffering

The goal of the buffering provided by the standard I/O library is to use the minimum number of read and write calls. This library also tries to do its buffering automatically for each I/O stream, obviating the need for the application to worry about it.

Three types of buffering are provided:

  1. Fully buffered. Actual I/O takes place when the standard I/O buffer is filled.

    • Files residing on disk are normally fully buffered by the standard I/O library.

    • The buffer used is usually obtained by one of the standard I/O functions calling?malloc?(Section 7.8) the first time I/O is performed on a stream.

    • The term?flush?describes the writing of a standard I/O buffer. A buffer can be flushed automatically by the standard I/O routines, such as when a buffer fills, or we can call the function?fflush?to flush a stream. Unfortunately, in the UNIX environment,?flush?means two different things:

    1. In terms of the standard I/O library, it means writing out the contents of a buffer, which may be partially filled.

    2. In terms of the terminal driver, such as the?tcflush?function in?Chapter 18, it means to discard the data that's already stored in a buffer.

  2. Line buffered. The standard I/O library performs I/O when a newline character is encountered on input or output.

    • This allows us to output a single character at a time (with the standard I/O?fputc?function), knowing that actual I/O will take place only when we finish writing each line.

    • Line buffering is typically used on a stream when it refers to a terminal, such as standard input and standard output.

    • Line buffering has two caveats:

    1. The size of the buffer that the standard I/O library uses to collect each line is fixed, so I/O might take place if this buffer is filled before writing a newline.

    2. Whenever input is requested through the standard I/O library from either (a) an unbuffered stream or (b) a line-buffered stream (that requires data to be requested from the kernel), all line-buffered output streams are flushed. The reason for the qualifier on (b) is that the requested data may already be in the buffer, which doesn't require data to be read from the kernel. Obviously, any input from an unbuffered stream, item (a), requires data to be obtained from the kernel.

  3. Unbuffered. The standard I/O library does not buffer the characters. For example:

    • If we write 15 characters with the standard I/O?fputs?function, we expect these 15 characters to be output as soon as possible, probably with the?write?function from?Section 3.8.

    • The standard error stream is normally unbuffered so that any error messages are displayed as quickly as possible, regardless of whether they contain a newline.

ISO C requires the following buffering characteristics:

  • Standard input and standard output are fully buffered, if and only if they do not refer to an interactive device.

  • Standard error is never fully buffered.

However, this?doesn't?tell us either of the following:

  • Whether standard input and standard output are unbuffered or line buffered if they refer to an interactive device

  • Whether standard error should be unbuffered or line buffered

Most implementations default to the following types of buffering:

  • Standard error is always unbuffered.

  • All other streams are line buffered if they refer to a terminal device; otherwise, they are fully buffered.



apue在線版本 unix編程環(huán)境online的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
通河县| 福州市| 怀安县| 教育| 扎赉特旗| 南宁市| 岑巩县| 五台县| 乌拉特中旗| 红安县| 文登市| 枣庄市| 福安市| 大石桥市| 巴林左旗| 河北区| 吴忠市| 策勒县| 屯昌县| 平舆县| 徐州市| 广平县| 水富县| 金溪县| 宁河县| 万山特区| 石城县| 龙游县| 富川| 益阳市| 灵丘县| 甘洛县| 莆田市| 庆阳市| 监利县| 台东县| 余姚市| 阿拉尔市| 米林县| 翁源县| 铜鼓县|