Storing mutable arrays in flash

Posted on
  • Hey there! Making this post separately from my other post so it's easier to find in search.

    I'm working on a project that stores an array of 572-byte-long Uint8Arrays in RAM, like so:

    var arrays = [];
    arrays.push(new Uint8Array(572));
    

    These sub-arrays are then read and written on the individual byte level. They're also not supposed to be read or written to extremely often, just maybe a couple dozen times a day.

    It's my understanding that this nested array is stored in RAM. However, I have a lot more free flash storage space on my Puck than I have free RAM. Is there any way to implement this same functionality (reading and writing individual bytes) while using the much larger flash storage?

  • Well, you can't create an array that way that you can write to, but you can make it so you can read from it and store it on flash. This should work:

    arrays.push(new Uint8Array(E.toArrayBuffer(require("Storage").read("test"))))
    

    So then all you have to do is write a function that'll handle writing the array. However it's worth noting that when you write the array (unless it was all 0xFF and you're setting individual bytes) it'll need to be re-allocated so will be at a different address, so you'd have to update it with the line above again

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Storing mutable arrays in flash

Posted by Avatar for Swordstone_ @Swordstone_

Actions