How to properly flush/sync files on Windows?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top