Linux buffer __linux

Source: Internet
Author: User

line buffering . In this case, the standard I/O library performs I/O operations when a newline character is encountered in the input and output. This allows us to output one character at a time, but only after a row has been written does the actual I/O operation. Row buffering is typically used when a stream involves a terminal.

First example: (Hello World)


Here, when we are not behind the Hello world, there is no Hello world in the results;


And when we add to it,


The result is this:


This is why, this is because of the existence of the buffer zone. The content is stored in the row buffer before it is printed on the screen. The content is output only if \ n is recognized.

Second Example: (Magic progress bar)

Speaking of the progress bar, we are all familiar with it. For example, like this:


How can such a progress bar be implemented in code?

To make a simple analysis, first we have to output the progress we've made, and the rest, and we have to show the percentages.

The code implementation is as follows:



Progress_bar is defined as a 102 space to store each progress;

Ch[] Indicates the buffering effect when the progress occurs;

' # ' stands for progress;

Fflush (stdout): To refresh the contents of the row buffer;

Usleep (100000): Sleep time, that is, the speed of control progress;

The results of the operation are as follows:



Today's buffer is first mentioned here ~ ~

Welcome to put forward valuable comments oh.

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.