You are reading a single comment by @fanoush and its replies.
Click here to read the full conversation.
-
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.
thanks for the answers!
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?