In C++, there is an std::fwrite() which writes a buffer to a file on disk.
Can you please tell me if there is any buffer inside that fwrite implementation?
i.e. if I call fwrite() multiple times (say 10 times), does it actually invoke file I/O 10 different times?
I am asking this for Ubuntu 10.04 environment.
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::setbufandstd::setvbuf.The functions in
cstdioare inherited from C. The preferred interface in C++ isfstreamandfilebuf.