gpt4 book ai didi

c++ - 刷新缓冲区是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 12:01:08 26 4
gpt4 key购买 nike

我在学习 C++,发现了一些我看不懂的东西:

Output buffers can be explicitly flushed to force the buffer to be written. By default, reading cin flushes cout; cout is also flushed when the program ends normally.

所以刷新缓冲区(例如输出缓冲区):这是通过删除缓冲区中的所有内容来清除缓冲区,还是通过输出其中的所有内容来清除缓冲区?还是刷新缓冲区意味着完全不同的东西?

最佳答案

考虑写入文件。这是一项昂贵的操作。如果在您的代码中一次写入一个字节,那么每次写入一个字节将非常昂贵。因此,提高性能的一种常用方法是将正在写入的数据存储在临时缓冲区中。只有当有大量数据时才将缓冲区写入文件。通过推迟写入,一次写入一大块,性能得到了提升。

考虑到这一点,刷新缓冲区是将数据从缓冲区传输到文件的行为。

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

后者。

关于c++ - 刷新缓冲区是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15042849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com