• I had re-flashed to 2.00

    Are you uploading the exact same code you did with the exact same firmware when it worked?

    The compiler shouldn't be an issue - it was a config problem on the server but the compiler itself didn't change.

    If you were to 'save on send' to 'direct to flash' that would give you a bunch more available memory. If you'd had that on before, and had changed it back, that would have broken things.

    I should add that it's not just that saving to flash gives you more memory, but it also doesn't save the function declarations to the command history, which means there's far less fragmentation.

    Stack

    Espruino doesn't allocate variables on the stack - they're all in one chunk of statically allocated memory. stackEndAddress really isn't a useful number for you to look at.

    E.getSizeOf()

    This scans the whole variable and everything it links (like if you ran trace(var)) - it's showing you the size of the object, all variables, all functions, and even any variables/functions in scopes that those functions were defined in.

    When you go down a level to output data, you might have two functions that are defined in the same scope. Both of those functions will bring in the same scope so will be more or less the same (huge) size.

    Is running process.memory() even needed as the board is just powered up, and the first initial 'send' is performed before any other tasks?

    Yes - because the act of sending (which is creating loads of functions and even executing them) can fragment memory.

    process.memory().free

    It's most likely fragmentation - especially as you're using over 2/3 of your memory. The quick explanation is:

    Unfragmented:  
    "XXXXXXXX        "
    allocating "XXXX" in one long chunk is easy
    
    Fragmented:  
    "X X X X X X X X "
    allocating "XXXX" in one long chunk can't be done
    

    In both cases there's the same amount of free memory, and the same amount used.

    This is one of the reasons I suggest that you just leave Espruino to do its own thing. If you created arrays the normal way:

        this.ad = new Uint8ClampedArray(256);
        this.ar = new Uint8ClampedArray(nArySizeRGB);
        this.ab = new Uint8ClampedArray(nArySizeRGB);
        this.ac = new Uint8ClampedArray(nArySizeRGB));
        this.af = new Uint8ClampedArray(nArySizeRGB);
        this.ag = new Uint8ClampedArray(nArySizeRGB);
    

    Espruino would automatically allocate flat strings for all those arrays, except if it couldn't find a big enough block of memory - in which case it would just allocate a normal String and continue perfectly fine, just a little bit slower.

    Of course if you are trying to write C code to access the raw data as a char array then you'll hit problems - but if you're using compiled JS or just normal JS you'll be fine.

  • Thr 2019.01.31
    Responding in three parts

    Thank you @Gordon for the clarifications and graphic.

    'Are you uploading the exact same code'

    Yes while adding small ~ten line functions saved one at a time. Was is happening, as array sizes are increasing, the code file could increase if I'm not removing an equivalent amount of bytes from that code file. I realize I'm near the max capability (without adding additional memory, a stock Espruino) of memory usage and trying to find the balance of what the max array size is, while leaving enough code play area for the end user.

    As I use Notepad++.exe with multiple tabs, bp and color, editing is much faster. A plausible condition that most likely occurred might be that as I had ~1000 blocks free, creating an instance and adding new code blocks in the console left pane shouldn't have given me any grief, which it wasn't. As it was late, it is quite possible that I hadn't re-tested the saved Notpad++ file on disk, by re-loading and re-sending. That was Sunday evening. When I attempted again on Monday, I was then loading a new file into a fresh IDE launch. My guess is that the new saved file was a fraction larger (how Windows/Notepad++ saves in blocks not bytes) than just copying the code functions into the IDE. So, when I attempted to use what I believed was the last working worked on code, the slightly larger file along with now larger arrays caused the low memory condition, which condition wasn't present during the end of the day, when it was working fine.

    ref: http://forum.espruino.com/conversations/­330191/#comment14595809

    Along with seeing the compiler error that I observed Monday at the same time and noticed in the other thread post, that there was an indication of a server configuration issue, I drew the wrong conclusion that the cause was on the server side as I hadn't changed the code source, as I had just loaded it.


    From #6 wasn't quite answered
    What is not making sense is during the creation of an instance that should only take ~2600 bytes, ~19,000 are actually getting used.

    164 * 16 = 2624 bytes calculated vs
    1236 x 16 = 19776 bytes actual free used

    Q: Does Espruino make an entire copy of the class functions (and called functions) when creating an instance using a constructor?
    Q: For clarification, a Uint is saved as ?? 16 byte JsVar e.g. Uint8ClampedArray(10) == ?? 16 byte JsVars?

    Trace shows 1 block but free bytes drops by 4 JsVars. Is there another way to reveal this that I'm missing? (an array of ten small ints should fit into one block or one JsVar, correct?)

    http://www.espruino.com/Internals

About

Avatar for Robin @Robin started