How to properly flush/sync files on Windows?

  • Thread starter Thread starter Arnold Hendriks
  • Start date Start date
A

Arnold Hendriks

Hello,

I wonder if anyone knows of some guide or reference on how to properly flush
file data to disk on Windows, or what Windows' own policy for disk and cache
flushing is, especially when memory mapped files are concerned. I've noticed
that all window NT and higher releases appear to be extremely lazy when
flushing data stored in memory mapped files to disk, sometimes not even
committing a dirty page to disk for weeks.

I'd like to know what one would have to consider when trying to perform
transactional and atomic writes to a file, to allow a safe rollback and
recovery for files even after a power failure.

Some of the questions I'm stuck with, and which don't appear to be dealed
with by the SDK documentation, are:
- Can you rely on FlushViewOfFile to have committed data to disk before
returning?
- Do you need to call FlushFileBuffers to properly flush a memory mapped
file? Does it have any effect at all?
- Does UnmapViewOfFile flush data to disk immediately, as soon as possible
or just whenever convenient? Does it return before or after flushing?

I'd appreciate any pointers.

Arnold
 
Back
Top