The datareader can't read buffer to the specified buffer directly? RRS feed

  • Question

  • Hi All,

    I write a class to handle the metro read/write just like the win32 api, but I found it can't read the buffer to the specified buffer directly, for example, I can use the win32 api ReadFile with the specified buffer. but in metro app, it should new a Platform::Array for reading, after that, copy the data from the Platform::Array to the destination memory, this way is inefficient, does anyone have any ideals? thanks!

    DataReader^ dataReader = ref new DataReader(readStream);  // IRandomAccessStream^ readStream
    create_task(dataReader->LoadAsync(static_cast<UINT32>(size))).then([this, dataReader](unsigned int numBytesLoaded)
         Platform::Array<byte>^ fileContent = ref new Platform::Array<byte>(numBytesLoaded);
         delete dataReader; // As a best practice, explicitly close the dataReader resource as soon as it is no longer needed

    • Edited by bszbrf Tuesday, July 31, 2012 2:09 AM
    Thursday, July 26, 2012 6:08 AM

All replies

  • There are helpers in the FileIO class that might be of use to you, specifically ReadBufferAsync.
    Thursday, July 26, 2012 4:55 PM
  • The FileIO class can't handle the large files, right? it will load all the data into the IBuffer? does anyone knows ? thanks
    • Edited by bszbrf Thursday, August 9, 2012 8:56 AM
    Friday, July 27, 2012 12:57 AM