locked
IRandomAccessStream - how it works inside?

    Question

  • i try to work with IRandomAccessStream and find one intresting thing:

    if i read some byte array from file, first time it took about 1.5 sec per 1kb, but after it reading perhaps as fast as this file is totally in RAM. At the same time i think about using kind of partial file caching in my app. So, is this partial cache will be helpful or it only wasting my and CPU time? 

    Tuesday, February 17, 2015 6:02 PM

Answers

  • It depends on where you're getting the IRandomAccessStream from.

    IRandomAccessStream is an interface which can be backed by several different implementations.

    Since you mentioned reading from a file you're probably using a StorageFile aimed at the file system. This will run through a broker process to read the file with privileges your app probably doesn't have and then provide the stream through IPC back to your app. This will be slower than reading the file directly, but as you note there is some caching going on.

    Whether a separate cache within your app is helpful or not depends on the app, how often and predictably it needs this data, etc. As with anything perf related, measure and address the slow spots. Don't optimise prematurely.

    • Marked as answer by Romka2411 Wednesday, February 18, 2015 1:33 PM
    Tuesday, February 17, 2015 6:37 PM
    Owner

All replies

  • It depends on where you're getting the IRandomAccessStream from.

    IRandomAccessStream is an interface which can be backed by several different implementations.

    Since you mentioned reading from a file you're probably using a StorageFile aimed at the file system. This will run through a broker process to read the file with privileges your app probably doesn't have and then provide the stream through IPC back to your app. This will be slower than reading the file directly, but as you note there is some caching going on.

    Whether a separate cache within your app is helpful or not depends on the app, how often and predictably it needs this data, etc. As with anything perf related, measure and address the slow spots. Don't optimise prematurely.

    • Marked as answer by Romka2411 Wednesday, February 18, 2015 1:33 PM
    Tuesday, February 17, 2015 6:37 PM
    Owner
  • yes i use the storage file. I writing my own audio decoder for FLAC files, so there i need a small amounts of data (up to ~16 kbytes). So i got an idea to read blocks 5mbytes and read data from it.

    What privileges you are talking about? Isnt StorageFile is the only way to read file in Windows Store App?

    Tuesday, February 17, 2015 6:53 PM
  • Windows Store apps don't have permissions to directly read files outside of their install and application data directories. To read files elsewhere (i.e. from libraries or from locations picked by the user) the app must use a StorageFile which can have an external broker process read the file with the user's full permissions instead of with the app's limited permissions.

    If your files are in the install or application data directories then the app can read them directly using standard C++ (fopen, etc.) or Win32 (CreateFile2, etc.) file IO

    Tuesday, February 17, 2015 6:58 PM
    Owner