is storage.compact() working ? #4726
Replies: 1 comment
-
Posted at 2018-12-27 by @gfwilliams There was actually an issue with writing that got fixed in firmwares after 2v00, so you could have a go with one of the 'cutting edge' builds I guess? The other thing is it might not have been able to compact because there wasn't enough RAM free to temporarily put the Posted at 2018-12-27 by Sacha Hi Gordon It would be very nice if you could implement a way to delete the flash for reuse without deleting the saved code. Like eraseAll() but without deleting the saved code. Thanks Posted at 2019-01-07 by @gfwilliams I'm afraid it's a bit difficult to handle nicely. Hopefully it'll get done at some point, but about the only way of getting it to work is to use other flash pages as temporary storage, which seems a bit of a waste of flash lifetime. Are you really in a situation where you absolutely need that ~2kB of flash memory? As I said above, once you start using other flash pages, those pages should still be able to be cleared automatically with eraseAll. Posted at 2019-01-12 by Sacha Hi Gordon I have several EspruinoWIFI distributed in my house. They all communicate to each other over IP. They know each other over UDP dynamicaly. Each espruino has a little "core" software saved. The over all configuration of all espruinos and additional code for different devices (Replays, Sensores, etc.) Every espruino will get the config and the individual needed additional device code to use and store it on the storage. So i have a full redundancy. Each espruino has stored the config of all espruinos and several espruinos has stored small code for They inform each other about the newest config version and the version of the small code pieces over udp. If a espruino has a newer version of the config for all espruinos or a newer version of code for connected That is the reason why i use a lot of the storage and get in trouble with it. That's why i'm looking for a way to wipe out everything except the saved code from the storage. Greetings Sacha Posted at 2019-01-14 by @gfwilliams Ahh, ok - that's tricky. I didn't realise it was Espruino WiFi. The Espruino WiFi is a bit oddball in that it only has one page for storage - a 64kB one - so there are no 'unused' pages it can free. If it can't get the contents of that page temporarily into RAM then it can't compact it. If you try:
It should show you roughly how much space is needed for each file. My guess would be that By default it'll try storing the data that's needed on the stack, but that's probably only around 10k or so, and I bet What you could try doing is:
Which will try and allocate space for Otherwise
But hopefully you should only ever have to do this when the WiFi board runs out of storage. Or... It looks like you're basically dynamically loading JS code? If that's the case then you probably don't need to use If you did that then you wouldn't need a Posted at 2019-01-14 by Sacha Hi Gordon With the save to flash option in IDE i'm not familiar. Do you have a link where i can read about this ? EDIT: Found: https://www.espruino.com/Saving Thanks Posted at 2019-01-14 by Sacha I've added to my wishlist a espruino wifi v2 with more RAM and more Flash ;-) Posted at 2019-01-15 by Sacha Hi Gordon After switching to "save to flash" in the IDE, i got a lot of more RAM free. After deleting all files except ".bootcde" and calling compact, nothing new. I do not get flashmemory back. Then i made a very ugly hack that seems to work!
After the reboot everything is working fine, storage is freed and ready for reuse ;-) Sacha Posted at 2019-01-15 by @gfwilliams That's great! Thanks for posting up the code - I'd forgotten about the issues you can hit if you're evaluating a function from Flash memory when you delete the flash! You could actually call Just to add if you're using almost too much memory there is a very small chance that I could definitely add the ability to use JsVars for storage when compacting, which would make it a little less likely that you have to do this. Potentially Espruino could also scan over all the functions inside itself and adjust the addresses such that Posted at 2019-01-15 by Sacha Hi Gordon Thanks for your help. How much mem will eval use ? I think i allocate some spare space ?
Posted at 2019-01-16 by @gfwilliams Honestly, I'm not sure. Mainly it'll be allocating the string, so:
would probably be pretty safe. Or... you could just do:
Which might be tidier/safer? Posted at 2019-01-16 by Sacha Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-12-25 by Sacha
Hello Gordon
I tried the storage function on FW 2.00
I transfered some files over wifi and stored them using the storage.write();
After deleting all files exept the saved code, i do call storage.compact().
But i do net get the space back ?
Thanks for the help.
Sacha
P.S.: A storage.eraseAll() function that removes everything exept the saved code would be nice (As an option for eraseAll() ) ?
Beta Was this translation helpful? Give feedback.
All reactions