• You can convert string via E.toArrayBuffer or E.toUint8Array or to any typed array var b=Uint16Array(E.toArrayBuffer(s))

    Or you can actually use Storage.readArrayBuffer since the typed array constructor can take offset and length into ArrayBuffer so something like b=Uint16Array(Storage.readArrayBuffer(..),byteOffset,length).
    All these will reuse underlying data in storage and won't create copies in RAM.

    Too bad there is no api to erase pages in the middle of storage files or create page-aligned storage file. That would give advantage of Flash module without the danger of breaking something. That would allow to do circular buffer in the file.

  • thanks for the answers!

    That would allow to do circular buffer in the file.

    A circular buffer is roughly the idea I am thinking about: as new data comes in it gets appended. When the file is full, old data gets overwritten. This should be possible pre-allocating enough space using also the size parameter in the write() method so that I can re-write on the same file with offset in the write() method to append. However, the documentation says that I can't rewrite the same position on the same file which brings two problems:

    Problem 1: I cannot rewrite older data. Workaround is to pre-allocate enough space and not overwrite. If space ends, I either create a larger file (and copy the existing content), or I give up and warn the user. I can live with the second, though not great.

    Problem 2: I need to keep track of what is the last byte that was written on the file, otherwise when I read back the file I will get all the "empty" data, the 0xFF bytes. Solutions are that I either impose that 0xFF cannot be used or that I keep track of the actual size of the storage file in a separate permanent memory, but Storage (and StorageFiles) would not work for this because I cannot rewrite them.

    Do you wise people have a better idea?
    Gordon, maybe you can extend the current API to support overwriting already written positions?

  • Gordon, maybe you can extend the current API to support overwriting already written positions?

    In general that's not possible. Flash memory can be erased only in blocks aligned to some boundary. Storage files occupy continuous area of flash but are not page aligned (to save space). However if there was some flag to create the file page aligned and there would be api to erase blocks it is doable.

About

Avatar for user107850 @user107850 started