PDA

View Full Version : QIODevice::Unbuffered on Windows. But why not.....



Morten
11th January 2016, 10:01
Hi all.

I was looking for an unbuffered write to disk using QSaveFile and noticed the QIODevice::Unbuffered ( http://doc.qt.io/qt-5/qiodevice.html#OpenModeFlag-enum ) mode, which seemed just like what I needed. Unfortunately the notes for that particular mode says

and limitations in the native API prevent QFile from supporting Unbuffered on Windows.

Knowing that Windows has both a FlushFileBuffers() function and FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aspx ) I an curious as to why QFile does not support QIODevice::Unbuffered as it seems to match pretty darn well with the flags mentioned.

Can anybody shed light on that matter?

Cheers,
Morten

anda_skoa
11th January 2016, 10:44
There might be a bug report detailing this, or a comment in the commit log for the Windows implementation of the file engine.
It could also be an outdated comment.

The cross-platform code always passes Unbuffered to the native code: https://code.woboq.org/qt5/qtbase/src/corelib/io/qfile.cpp.html#_ZN5QFile4openE6QFlagsIN9QIODevice1 2OpenModeFlagEE

The Windows implementation doesn't seem to check for this flag though: https://code.woboq.org/qt5/qtbase/src/corelib/io/qfsfileengine_win.cpp.html#_ZN20QFSFileEnginePriva te10nativeOpenE6QFlagsIN9QIODevice12OpenModeFlagEE

Maybe CreateFile2() doesn't have the necessary capability?

Cheers,
_