I’m saving a file on an USB drive and need to make sure that it’s completely written to avoid corruption in case the USB drive is not removed properly.
Well I’ve done some research and it seems this is possible via calling the FlushFileBuffers Win32 function.
But the problem is, I’m saving using boost::serialization and thus don’t have access to the actual file HANDLE.
I wonder what is the proper way to flush the file? Thanks!
I’m saving a file on an USB drive and need to make sure that
Share
Call ostream::flush on the output stream you created your archive object with:
You could also just let the objects go out of scope which should flush everything:
Note, you still need to properly unmount your USB device. Flushing the data just makes sure it gets from userland into the kernel, but the kernel can also do it’s own buffering.