How to ensure all data has been physically written to disk?

后端 未结 7 1196
执念已碎
执念已碎 2020-11-27 05:44

I understand that .NET FileStream\'s Flush method only writes the current buffer to disk, but dependent on Windows\' disk driver and the hard disk firmware this is no guaran

7条回答
  •  [愿得一人]
    2020-11-27 06:09

    Well, you could close the file... that would probably do it. In reality, with HAL abstraction, virtualization, and disk hardware now having more processing power and cache memory than computers did a few years ago, you're going to have to live with hoping the disk does its job.

    The transactional file system never really materialized ;-p Of course, you could perhaps look at using a database as a back end, and use the transaction system of that?

    Aside: note that not all streams even guarantee to Flush() - for example, GZipStream etc retain a working buffer of uncommitted data even after a flush - the only way to get it to flush everything is to Close() it.

提交回复
热议问题