What's the difference between FileStream.Flush() and FileStream.Flush(True)?

前端 未结 3 648
时光说笑
时光说笑 2021-02-18 12:33

MSDN says that FileStream.Flush(True) \"also clears all intermediate file buffers.\".

What does \"all intermediate file buffers\" mean exactly?

3条回答
  •  野性不改
    2021-02-18 13:14

    When you call Flush() or Flush(false), FileStream "copies to the file any data previously written to the buffer and clears the buffer (except for its encoder state)". Buffer here means internal buffer of FileStream class. And copying to file is not writing data to disc. It's just passing data to OS.

    But, IO operations in Windows OS are also buffered - writing data to disk could be postponed until system will be ready to do it. So, clearing all intermediate buffers enforces writing buffered data to disc. Buffers here means Windows internal buffers [File system cache].

    BTW when you close file, all buffered data will be written to disc automatically. So, you need this stuff only if you need data to be flushed before file handle will be closed.

提交回复
热议问题