Sign in to follow this  

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

This topic is 3786 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
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

This topic is 3786 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this