question about CreateFile and FILE_FLAG_WRITE_THROUGH

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone,


Suppose I have a file created with FILE_ATTRIBUTE_NORMAL attribute. I think
it means attribute FILE_FLAG_WRITE_THROUGH is not enabled. Is my
understanding correct?

And I think if I do not enable the FILE_FLAG_WRITE_THROUGH attribute, even
if flush operation (function call) will not *truly* dump data to disk. Is my
understanding also correct?

So, my question is, when will the data be dumped to disk -- only when we
close the file?


thanks in advance,
George
 
Thanks Bruno,


Do you mean even if I only invoke write API (without flush) when in
FILE_FLAG_WRITE_THROUGH mode, the OS buffer and the physical content on disk
are the same?

Another question is, if FILE_FLAG_WRITE_THROUGH mode is not enabled, how
will data lose? (I think if FILE_FLAG_WRITE_THROUGH is not enabled, we could
invoke flush, and whether or not FILE_FLAG_WRITE_THROUGH is enebled, flush
will definitely write OS buffer data to external disk. Is my understanding
correct?)


regards,
George
 
Do you mean even if I only invoke write API (without flush) when in
FILE_FLAG_WRITE_THROUGH mode, the OS buffer and the physical content on disk
are the same?

Almost. if FILE_FLAG_NO_BUFFERING is in effect, the write operation will go
through the cache and writes directly to the hard disk.
If that flag is not used, write operations go to the system cache but get
flushed immediately. This is a subtle difference and has to do only with
asynchronous performance characteristics. The data arrives on disk at almost
the same time. only the write operation finishes a bit earlier.
Another question is, if FILE_FLAG_WRITE_THROUGH mode is not enabled, how
will data lose? (I think if FILE_FLAG_WRITE_THROUGH is not enabled, we could
invoke flush, and whether or not FILE_FLAG_WRITE_THROUGH is enebled, flush
will definitely write OS buffer data to external disk. Is my understanding
correct?)

flush will definitely get your data to disk.
if you don't flush and the computer loses power or crashes, it is impossible
to predict how much data you lose.

Note that if your computer loses power before the hard disk internal cache
is written to disk, you will stil lose some data.
 
Thanks Bruno!


The last question, are there any comprehensive samples/documents about
FILE_FLAG_WRITE_THROUGH technology (from any aspect is ok, like internal
implementation, performance, ...) you would like to recommend?

Bruno van Dooren said:
It is up to the system to make that decision unless you flush the data
yourself by calling flush. FILE_FLAG_WRITE_THROUGH has no direct documented
effect on flush.


Yes.

--
Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"


regards,
George
 
Back
Top