Flush disk write cache

后端 未结 6 1202
天涯浪人
天涯浪人 2020-12-17 02:18

When the policy for a disk in Windows XP and Vista is set to enable write caching on the hard disk, is there a way to flush a file that has just been written, and ensure tha

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 02:51

    You should not fix this at the time you close the file. Windows will cache, unless you open the file passing FILE_FLAG_WRITE_THROUGH to CreateFile().

    You may also want to pass FILE_FLAG_NO_BUFFERING; this tells Windows not to keep a copy of the bytes in cache.

    This is more efficient than FlushFileBuffers(), according to the CreateFile documentation on MSDN.

    See also file buffering and file caching on MSDN.

提交回复
热议问题