The CreateÂFile
function has two related flags: FILE_
and FILE_
. These flags can be set independently, but they sort of work together.
First, let’s look at FILE_
. Setting this flag prevents operations on the handle from going through the disk cache. Reads come directly from the disk, and writes go directly to the disk.
The FILE_
flag increases the urgency with which write requests are sent to the disk. Setting this flag forces writes to go to the disk immediately, and combining this flag with FILE_
adds the additional urgency of telling the disk controller to flush the data out of its internal cache.
So let’s fill out a table.
 | NO_ |
||
---|---|---|---|
Clear | Set | ||
WRITE_ |
Clear | Writes go into cache Lazily written to disk No hardware flush |
Writes bypass cache Immediately written to disk No hardware flush |
Set | Writes go into cache Immediately written to disk Hardware flush |
Writes bypass cache Immediately written to disk Hardware flush |
Bonus reading: We’re currently using FILE_
and FILE_
, but we would like our WriteFile to go even faster.
I think some of the confusion stems from the conceptual conflation of "buffering" with "caching." Caching is keeping data in memory in anticipation of future reads--speeding up the reads by avoiding going back out to the slower media. Buffering is about collecting data in blocks that are compatible with the "sector size" of the media.
Disk drives won't let you read or write four bytes of data at an arbitrary offset. You can only...
What is the size of atomicity with a hard drive? I always wondered how journaling was possible.