3 ms·
Are we continuously told in our courses to flush() the file so that it gets written to disk?
by passion__desire 3y ago
Are we continuously told in our courses to flush() the file so that it gets written to disk?
- bcrl 3y agoIf you're talking about fflush() from the C standard libray, fflush() doesn't write to disk. It pushes writes from the FILE's buffer to the kernel and drops any read data that has been cached. The C standard library doesn't really provide you with all the tools needed to commit writes to disk fully.
- 95014_refugee 3y agoHopefully not, because that murders performance. The caching exists for a reason, let it do its thing. If you care about data integrity, you don’t trust the disk anyway, so flushing to the disk isn’t enough.
- Filligree 3y agoThere's fsync. Unfortunately, if you want atomicity but not durability you have ~zero options on common filesystems. (On ZFS and bcachefs you can get that by disabling syncs completely; they never reorder writes in a visible manner.)