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

歡迎光臨散文網(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ó)家法律
柘城县| 乌恰县| 彭州市| 榆树市| 通榆县| 包头市| 中宁县| 乐至县| 资兴市| 永安市| 勃利县| 时尚| 蒙山县| 禹城市| 鄂伦春自治旗| 开阳县| 南召县| 太仆寺旗| 镇康县| 辉县市| 怀来县| 贵阳市| 房产| 东源县| 宁安市| 赤水市| 定远县| 墨竹工卡县| 台江县| 黄浦区| 乐山市| 乡宁县| 固始县| 阳谷县| 潼南县| 石柱| 正镶白旗| 昔阳县| 罗源县| 周口市| 葫芦岛市|