• I think there are a few things that could help you out - some of which Robin already mentioned:

    • You can do a = new Uint8Array(10);a.set("Hello") to write direct into an ArrayBuffer - it'll be pretty fast. I'm not sure accepting a string is spec compliant but it works great on Espruino.
    • new DataView(uint8array.buffer) is very fast - no copies or anything
    • E.toString will create a flat string from whatever you give it - but the allocation of a flat string can be slow
    • E.toUint8Array/E.toArrayBuffer may also help
    • it should be reasonably efficient to append to a string as long as the string isn't too big

    But yeah, doing something like:

    var buf = new Uint8Array(200);
    var idx = 0;
    SerialX.on('data',function(d) {
      buf.set(d,idx);
      idx += d.length;
      // ...
    });
    

    works fine

About

Avatar for Gordon @Gordon started