C Standard I/O Buffer: Full buffer and row Buffer

Source: Internet
Author: User

Iso c Standard I/O provides full buffering and row Buffering

Full Buffer: During I/O operations, real I/O operations are performed only when the I/O buffer is filled up. Therefore, the buffer in the full buffer can be automatically refreshed by the standard I/O routine, that is, when the buffer is filled up, another method is to call the fflush function for Refresh.

Row Buffer: Perform real I/O operations when the input/output encounters a line break. For row buffering, the buffer length of each row of the standard I/O is fixed, so as long as the buffer is filled up, the buffer is refreshed even if there is no line break.

Of course, standard I/O also provides a type without buffering, that is, it does not buffer characters.

In this case, where are the I/O operations used for full buffering and row buffering.

Iso c Requirements:

  • They are full buffering only when the standard input and output do not involve interactive devices (terminal devices.
  • Standard errors are not full buffering.

However, this does not tell us whether the standard input/output is a row buffer or not, and whether the row buffer is not a buffer when a standard error occurs. Many systems (FreeBSD, Linux, Mac OS, and Solaris) use the following buffer types by default:

  • If the standard input and output involve terminal devices, they are row buffering; otherwise, they are full buffering.
  • Standard errors are not buffered.

We all know that shell defines three file descriptors for each process: 0, 1, 2. These three file descriptors are associated with the standard input, standard output, and standard error output of the process respectively. Replace the three constants in the unistd. h header file with stdin_fileno, stdout_fileno, and stderr_fileno. In iso c, it corresponds to stdin, stdout, and stderr respectively.

C Standard I/O Buffer: Full buffer and row Buffer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.