What does flushing the buffer mean?

前端 未结 3 465
别那么骄傲
别那么骄傲 2020-11-27 10:28

I am learning C++ and I found something that I can\'t understand:

Output buffers can be explicitly flushed to force the buffer to be written. By def

3条回答
  •  有刺的猬
    2020-11-27 11:00

    Consider writing to a file. This is an expensive operation. If in your code you write one byte at a time, then each write of a byte is going to be very costly. So a common way to improve performance is to store the data that you are writing in a temporary buffer. Only when there is a lot of data is the buffer written to the file. By postponing the writes, and writing a large block in one go, performance is improved.

    With this in mind, flushing the buffer is the act of transferring the data from the buffer to the file.

    Does this clear the buffer by deleting everything in it or does it clear the buffer by outputting everything in it?

    The latter.

提交回复
热议问题