locked
Unbuffered IO in c++ Windows Store application

    Question

  • Hello,

    I am using CreateFile2 to open a file and passing the FILE_FLAG_NO_BUFFERING flag to enable unbuffered IO. According to the following document:

    File Buffering (Windows)

    I then need to obtain the Physical Sector size in order to use this method of file access. The problem is that the APIs suggested by the document are not supported in Metro Style applications and I was wondering if there was another API that I could use to obtain the needed information.

    I wanted to avoid to use WinRT libraries because my code lives in a static library which is meant to be used from both desktop and windows store apps, and it would complicate things a little.

    Thank You,

    Best Regards,

    Joe

    Saturday, December 29, 2012 9:17 PM

All replies

  • The FILE_FLAG_NO_BUFFERING eliminates all read-ahead file buffering and disk caching, so that all reads are guaranteed to come from the file and not from any system buffer or disk cache. When using FILE_FLAG_NO_BUFFERING, disk reads and writes must be done on sector boundaries, and buffer addresses must be aligned on disk sector boundaries in memory.

    As you know, both VirtualAlloc and GetSystemInfo function are not available for Windows Store apps.

    However, there is no other alternative API to obtain sector size in Windows Store app as well.


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 2, 2013 8:03 AM
    Moderator
  • Thanks for the answer Robin, but I think this is a huge shortcoming.

    Having to guess the size of the sector in order to use unbuffered IO doesn't make sense. I think this is a design flow, you either have a feature or you don't have it.

    Correct design would be to either have a function that provide the sector size or disable unbuffered io altogether.

    The fact that VirtualAlloc is not available or that no additional heap can be created are also a huge shortcomings.

    In the end it feels like Windows Store apps would correspond to: "Windows for dummies"!!!

    Thanks again

    Regards,

    Joe

    Wednesday, January 2, 2013 5:46 PM