Storage free space reducing on each save

Posted on
  • Hi all,

    I've seen that each time I write code onto Storage using IDE free space read by "About" app is reduced.
    This happens even if I simply overwrite same piece of code one or more times.
    Is it real?
    What I can do to avoid it?

    Sorry but I'm confused.

  • Maybe I've found the solution:

    require("Storage").compact();

    Is it correct?

  • Sat 2021.03.20

    'even if I simply overwrite same piece of code one or more times'

    Would you please post your code snippet that demonstrates the write and then read process.
    By chance are the modes mixed?

    ref: http://www.espruino.com/Bangle.js+Storag­e#line=59

    4th bullet below heading 'A few things are going on here:'

    'A file created with require("Storage").open is different to one created with require("Storage").write since it is designed to be appended to. As such you can only access the files with require("Storage").open and not with require("Storage").write/read/erase/etc'­


    'even if I simply overwrite same piece of code one or more times'

    It would help by posting the results alternating between each of these instructions demonstrating the 'overwrite' as is observed.

    http://www.espruino.com/Reference#t_l_St­orage_getFree

    http://www.espruino.com/Reference#l_Stor­age_write

  • Hi @Robin,

    first of all thanks for your reply.

    I think there is a misunderstanding, maybe I've messed up my explanation.

    I've experienced the following using IDE:

    1. get code of MorphingClock from my Bangle storage using specific icon (4 disks);
    2. modified code and tried it with success using RAM upload function;
    3. overwrite existing mclock.app.js code into Bangle storage using specific icon (chip icon with drop down menu);

    After each cycle of changes made as exposed in the pointed list above, looking at 'About' app I've seen my free disk space reduced.

    For each cycle, space consumption increased of the amount of bytes occupied by code uploaded; like it was written n times in place of one time in the same position.

    Yesterday I've discovered 'require('Storage').compact()' function and I've tried it with success.
    Now space consumption value is as expected.

    No new files were created during changes or coding, neither inside the code nor through upload function. I've made changes and then saved them on the same file (mclock.app.js) n times, nothing more.

    After this I think this behaviour is normal, but my question is what about to happen if space consumption reading would reach the maximum.

    Thanks for patience.

    Massimiliano

  • Yes, it is normal, it will call compact automatically when there is no free space when trying to create file
    https://github.com/espruino/Espruino/blo­b/ea8ba1c2ff9c9bfa1d19f5c5911818e0a43c7f­4f/src/jsflash.c#L454

  • As @fanoush says - compact gets called automatically.

    It helps decrease flash wear, because the same bits of flash memory don't get written all the time.

  • Thanks for explanation.
    It solved my doubt.

    Massimiliano

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

Storage free space reducing on each save

Posted by Avatar for user123768 @user123768

Actions