Writing files with overlapping I / O with recording a file in a separate stream

Is there any advantage to using writing files with overlapping IOs on Windows, but just writing the file to a separate stream that I create?

[Edit - note that I am recording a file without system caching, that is, I use the FILE_FLAG_NO_BUFFERING flag in CreateFile)

+7
c ++ windows file-io
source share
4 answers

Since all entries are cached in the system cache by default, it does little to overlap I / O or create a separate stream for writing at all. Most WriteFile calls are kernel-only memcpys, which are lazily written to the OS disk in an optimal way with other messages.

You can, of course, disable buffered I / O via the flags for CreateFile, and then there are advantages to performing any asynchronous I / O - but you probably did not / should not.

Edit

The OP clarified that they actually use unbuffered I / O. In this case, the two proposed solutions are almost identical; internally, Windows uses a thread pool to serve asynchronous I / O requests. But hypothetically, Windows may be more efficient because half of them are implemented in the kernel, fewer context switches, etc.

+5
source share

One of the advantages of overlapping I / O is that it allows a single thread (or, most often, a thread pool) to process an arbitrary number of I / O requests simultaneously. This may not be an advantage for a single-user desktop application, but for a server application that can receive I / O requests from many different clients, this can be a major victory.

+2
source share

Perhaps due to I / O overlap in Windows, it will be indicated that Windows will write the file at its own time in the background, as opposed to spawning a whole new stream and participating in the blocking operation?

+1
source share
+1
source share

All Articles