• Sat 2018.10.06

    Not strong enough with Espruino debugger to solve this, as my pointer offsets appear to be the culprits

    Trying to convert this working code block to inlineC

    for( var i=0; i<this.ac.length; i++ ) {
        var nRGBCur = this.af[i];
        this.ac[i] = this.ag[nRGBCur];

    Leaving out the overhead ex:

    var addrdest = E.getAddressOf(dest,true);

    Have tried

    for( int i=0; i<size; i++ ) {
      int nRGBCur = *(datasrc[i]);
      *(datadest++) = *(datag[nRGBCur]);


    int nRGBCur = *(datasrc+i);
    *(datadest++) = *(datag+nRGBCur);

    but both corrupt memory as can be seen by viewing 'this' and instantiated variable contents in IDE console.

    My belief is the arrangement of the JSVars in memory, thus the offsets are off. e.g. what the pointers point to

    ref: http://forum.espruino.com/comments/14431­325/

    I am able to walk the array one element at a time in succession (not what I'm after)

    for( int i=0; i<size; i++ ) {
      *(datadest++) = *(datasrc++);

    I understand the pointer points to the address and the address value is incremented to the next higher address.
    What I need is the pointer points to the address and the address is incremented to an offset into that array at that address.

    Any insight greatly appreciated.

  • Sun 2018.10.07

    Well, it is amazing how a fresh look at things may solve an issue.

    It was the second example as I expected it should be

    int nRGBCur = *(datasrc+i);
    *(datadest++) = *(datag+nRGBCur);

    The issue was option base one rather than zero, which made the size of the array one too large. Amazing what happens when one marches off the end of an array by one byte!!

  • Off by one, the rue of existence ...

  • @Robin, you may take a look at the https://www.espruino.com/Internals page that talks about variables and memory layout - and btw, there you also find how ESPRUINO JavaScript is processed: Parser (regarding 'byte code' mentioned in a different conversation of yours. Conversation about memory usage (google for Espruino Internals Variables, Memory, Storage) are a good information source as well.

    There are certain types of objects - pointed to by variables - that have all their bytes as ducks in a row, where others have them in units of a few daisy chained - latter was first and only way Espruino handled memory for a long time, until performance hit the ceiling, mainly by trying to drive these colored RGB LED strips, and it was not enough, so the module became built-in natively implemented...

    Looking at the interpreter's source may help you as well with understanding to take advantage of your C desires and skills..

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

Need someone strong in pointer skills and E.compiledC for a simple snippet

Posted by Avatar for Robin @Robin