Jump to content
  • Advertisement
Sign in to follow this  
fpsgamer

[C++]Techniques for safe file i/o

This topic is 4005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a portion of an application that needs to write data to disk frequently. It is exceptionally important that this data is always written successfully. I thought of writing first to a temporary file, if the write succeeds I delete the existing file and rename the temporary file. I also read briefly about the system call mmap. If I understand correctly this will map a file or device to be mapped in main memory. Would using that provide any extra assurance that data will be written successfully?

Share this post


Link to post
Share on other sites
Advertisement
you can use flush() to force the cached data to be written to disk.

in std::ostream this is just my_stream.flush(); IIRC.
in stdio this is fflush(FILE); IIRC.

Share this post


Link to post
Share on other sites
Be careful how often you write to file. I accidentally left some debug file writing in a release version and it cut the frame rate in half.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!