I found some legacy company code that was using an std::fstream
and calling fs.flush()
after each write, then fs.sync()
each time a certain amount of data were written to the stream. This code only needs to do output operations, not input ones.
std::fstream fs(filename, ios::out | ios::binary);
fs.write(buff, size);
fs.flush();
if (/* needs to sync */) {
fs.sync();
}
This is surprising me as I usually use std::ofstream
for output-only IO operations and because this class actually does not have the sync()
method.
Since std::ofstream
does not have the sync()
method, does it makes sense to use std::fstream
and sync()
for output-only IO operations?
In my specific case, should I keep using std::ofstream
and call flush
without thinking about sync
?
Aucun commentaire:
Enregistrer un commentaire