fwrite是否缓冲输出

fwrite是否缓冲输出

本文介绍了fwrite是否缓冲输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,有一个,它将缓冲区写入磁盘上的文件。

In C++, there is an std::fwrite() which writes a buffer to a file on disk.

你能告诉我, fwrite implementation?

Can you please tell me if there is any buffer inside that fwrite implementation?

ie如果我调用fwrite()多次(说10次),它是否实际调用文件I / O 10不同的时间?

i.e. if I call fwrite() multiple times (say 10 times), does it actually invoke file I/O 10 different times?

我要求这是Ubuntu 10.04环境。

I am asking this for Ubuntu 10.04 environment.

推荐答案

,它被缓冲。缓冲区的大小由 BUFSIZ 定义。 (感谢@ladenedge。)十个足够大的操作将导致十次系统调用。

Yes, it is buffered. The size of the buffer is defined by BUFSIZ. (Thanks @ladenedge.) Ten sufficiently large operations will result in ten system calls.

您还可以使用和。

You are also allowed to set your own buffer using std::setbuf and std::setvbuf.

cstdio 中的函数从C继承。C ++中的首选接口为 fstream filebuf

The functions in cstdio are inherited from C. The preferred interface in C++ is fstream and filebuf.

这篇关于fwrite是否缓冲输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:46