Random File IO

I just finished reading the following tutorial:
http://www.learncpp.com/cpp-tutorial/187-random-file-io/

I was hoping someone could point me in the right direction, on where I can learn about efficiently reading and writing random file io, and how that translates to actual hardware requests.

For example, I'm guessing C++ is buffering a lot of input/output and attempting to batch the requests -- but I want full control over how the hardware behaves so I can toy with some test programs.

Thanks,
Stephen
Last edited on
It isn’t just C++ doing magic buffering — the underlying OS will also buffer.

Don’t try to get around it. If you want to make sure that the OS has been properly instructed to synchronize output to disk, perform a flush. Otherwise, assume that the system works as described to you by the language.

If you want more direct file access, consider using memory-mapped file I/O. Boost lets you do it in a platform-friendly way. Two examples:
https://techoverflow.net/2013/03/31/mmap-with-boost-iostreams-a-minimalists-example/
https://www.eriksmistad.no/memory-mapped-files-using-the-boost-library/

Keep in mind, though, that memory-mapping does not imply instant I/O to disk — it is still up to the OS when to do it.

Good luck!
Topic archived. No new replies allowed.