• Wed 2017.02.22

    I felt this more of a topic for 'General' but also specific to the 'ESP8266' Will understand if needed to be moved to the other category.

    As I attempt to clean up lines of code that will no longer fit in the available memory space, I notice that the number of bytes attempted to be saved increases, even after deleting both lines of code and comments.

    The error 'Too big to save to flash' occurs and from a quick observation, it can be seen that the intended number of bytes 13139 is larger than the 12284 allotted, despite 1/3 of memory remaining.

    Why, when there is 1/3 of the available space remaining, the inability to save a few additional lines of code?

    1v89 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
    >
    { "free": 415, "usage": 1285, "total": 1700, "history": 1 }
    >save()
    =undefined
    Erasing Flash.....
    Writing...............
    ERROR: Too big to save to flash (13139 vs 12284 bytes)
    Deleting command history and trying again...
    Erasing Flash.....
    Writing...............
    ERROR: Too Running onInit()...
    [L914] inside onInit()
    

    I removed at least thirty lines of code and twenty comment lines, yet the total bytes only decreased by 48 and the memory usage block doesn't even budge. I expected around 1000+ bytes to decrease.

    Writing...............
    ERROR: Too big to save to flash (13091 vs 12284 bytes)
    Deleting command history and trying again...
    
    >process.memory()
    ={ "free": 415, "usage": 1285, "total": 1700, "history": 1 }
    >
    

    So I became more aggressive and whacked another fifty lines and to my surprise the number of bytes jumped up to 17568, despite aggressive removal of code lines. With the usage now lower and free space now larger, I now expected to be able to easily save. But as one can see, the save() routine wont allow this smaller block of source code to be archived.

    Writing....................
    ERROR: Too big to save to flash (17568 vs 12284 bytes)
    Deleting command history and trying again...
    
    >process.memory()
    ={ "free": 532, "usage": 1168, "total": 1700, "history": 1 }
    >
    

    Is this the memory leaking that was described here?:
    http://forum.espruino.com/comments/13469­254/

    I read over:
    http://www.espruino.com/ESP8266_Flashing­
    http://www.espruino.com/Internals
    http://www.espruino.com/Performance
    but didn't locate suitable info other than 'Variables are usually stored in fixed-size 16 byte blocks'

    The offsets from an ESP-12 allow for 0x3FFF or 3 * 16 * 256 = 12288 bytes which I can see is used for the 12284 value
    0x3FC000
    0x3FE000
    0x400000

    But the other values are more puzzling.

    Q: How much in bytes is the actual space indicated by 'free'

    Q: How large are these blocks re: total 1700

    Q: What is the relationship between the total blocks 1700 and used bytes 12284

    Q: Are comments stripped from the source before 'Send to Espruino'? e.g. are they counted in used byte count?

    Q: Why couldn't I save this code block despite having ample free space?

About

Avatar for Robin @Robin started