473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

question about CreateFile and FILE_FLAG_WRITE_THROUGH

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
Jan 16 '07 #1
3 4147
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

"Bruno van Dooren [MVP VC++]" wrote:
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?

Indeed.
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?

No.
FILE_FLAG_WRITE_THROUGH causes writes to go directly system cache or disk,
depending on whether FILE_FLAG_NO_BUFFERING is set.
But this pertains to write operations e.g. via WriteFile.

If you flush the file, all buffered data is written to disk.
From MSDN:
"The FlushFileBuffers function writes all of the buffered information for
the specified file to disk."

The flags you mentioned affect the behavior of write operations.
If write through is enabled, a write operation is conceptually identical to
a normal write followed immediately by a flush
So, my question is, when will the data be dumped to disk -- only when we
close the file?

No, also when you flush.

--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Jan 17 '07 #2
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.
--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Jan 17 '07 #3
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 [MVP VC++]" wrote:
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.
I do not fully agree with you that the data will be flushed to disk
*immediately* after invoking flush when FILE_FLAG_WRITE_THROUGH is not set.
According to MSDN API description, it is up to OS that when the data will be
flushed to disk (maybe per 512 byte basis, maybe per 1k byte basis, ...) --
not actually *immediately*. Any comments?

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.
Another question is, I think whether or not FILE_FLAG_WRITE_THROUGH is
enabled, when we invoke flush (ignore system fail -- like power fail issue)
command, the content of OS buffer will be 100% definitely flushed on disk. Is
that correct?

Yes.

--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

regards,
George
Jan 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
11
by: kazack | last post by:
I am under the the impression that a variable is what is stored in a memory address and a pointer is the memory address of the variable? I was looking to use a function that does not return a...
0
by: Nitin Narang | last post by:
I have a piece of code which is moved to .NET VC7 recently from VC6 and there has been an apparent change in behavior using CreateFile/Writefile functionality. I am creating a file on a shared...
7
by: Rhino | last post by:
Since I haven't been able to find out yet how to get my Eclipse debugger to step through my Java UDF code, I am adding old-style File I/O debugging to some of my UDFs. I'm not sure of the best way...
3
by: Antoine | last post by:
Hello, I'm writing a program to send requests to my wlan pocket pc device (UIO1: driver) in C#. Here how I import CreateFile functions from coredll.dll with DllImport: public static extern...
4
by: JLW | last post by:
I'm having alot of difficulty with this one. I have seen no less than 20 different ways to use this function with a named pipe. I'm trying to use \\.\TAPE0 (TapeDrive). Here's my decleration: ...
1
by: Silesian | last post by:
I realize that this is a newbie question but maybe someone will be able to tell me what am I doing wrong. createFile() gets called each time I have the user generate some numbers which then get...
5
by: Andrew Clark | last post by:
Hello, Thanks for all replies on this subject. I still cannot get CreateFile to retun a good value though. I went to PInvoke.net and saw the VB.NET declaration of this function: ...
8
by: news.microsoft.com | last post by:
Hello, i'm having problems to call a api dll in vb dot net. I absolutely want to use this api call and none of the frame calls. This is my declaration: ***************** Public Structure...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.