• Yes, now it is fixed, thanks. I hoped it would help with memory fragmentation in my case so that E.toString() would work on the font but it wasn't enough. There is probably too much fragmentation already so even without this locked/leaked SPI variable(s) it doesn't work and still return undefined. Also E.defrag() does not help. The E.dumpFragmentation() is useful as it shows the buffer allocated by Graphics.createArrayBuffer is not created as flat string. After deleting fnt variable flat strings are still there and areas freed (marked in blue) are used by normal variables '#' not '='
    So E.toString() tries to do a copy and fails as there is no continuous space.

    >var fnt=createFont(0x199e0e,322,40,64,14,fal­se);
    ={
      font: new ArrayBuffer(4480),
      width: 40, height: 64 }
    >process.memory().free
    =260
    >E.toString(fnt.font)
    =undefined
    >E.defrag()
    =undefined
    >E.toString(fnt.font)
    =undefined
    >trace(fnt.font)
    #1845[r1,l1] ArrayBuffer (offs 0, len 4480)  #1822[r1,l0] String [374 blocks] "\0.....................
    =undefined
    
    

    1 Attachment

    • Capture.PNG
  • That's a shame - still, you've got extremely high memory usage there.

    IIRC the defrag won't move flat strings - I was concerned about what you'd mentioned earlier - moving stuff that you had a pointer to.

  • Yes, memory usage is high, this is actually with code uploaded to ram so it can be better. Still before trying to create the font, ther are like ~500 variables free so was hoping this could work. This is more like stress test of Espruino memory, not that I couldn't do it better. There are quite a lot of flat strings, more than I expected, any way to find them? Can it be the javascript code that is uploaded?

    I guess the main thing from this is that it would be nice to get non-flat string from the array buffer somehow so it is not need to call E.toString on large arrays.

    IIRC the defrag won't move flat strings - I was concerned about what you'd mentioned earlier - moving stuff that you had a pointer to.

    Maybe it could be some flag to E.defrag() to force it when called explicitly. I can handle that in my own code if I can call it myself with that flag when needed, now sure how much espruino internal usage of flat strings would break (if there is any).

  • There are quite a lot of flat strings .... Can it be the javascript code that is uploaded?

    Yes - if there's a decent size string to allocate Espruino will try and use a flat string since it's more space efficient, so that could be it. Using trace would tell you what's flat and what isn't.

    And yes, potentially compacting flat strings could be added. I think it just felt non-trivial at the time so I didn't add it.

    But yeah, ideally there'd be a way to get the string from an arraybuffer. I guess I could add a non-standard function like ArrayBuffer.getBackingString?

  • I guess I could add a non-standard function like ArrayBuffer.getBackingString?

    Yes, if E.toString is taken and not usable for this then why not. .asString() or .bufferString() could be shorter but naming is always hard :-) Also depends a bit how exactly it will work. For this code

    a1=new Uint8Array([1,2,3,4,5]);
    a2=new Uint8Array(a1.buffer,0,3)
    

    can I call a2.getBackingString() to get string of 3 bytes or is this method for underlying a2.buffer buffer. In first case there could be a2.buffer and a2.bufferString or a2.bufferAsString. For second case a2.buffer.getBackingString makes sense.

  • can I call a2.getBackingString() to get string of 3 bytes

    Afraid not - I couldn't make it reference just part of a String, it's got to be the whole thing

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

setFontCustom bitmap format vs vertical_byte:true - GT24L24A2Y fontchip in F07 fitness tracker

Posted by Avatar for fanoush @fanoush

Actions