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;
// ...
});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I think there are a few things that could help you out - some of which Robin already mentioned:
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 anythingE.toString
will create a flat string from whatever you give it - but the allocation of a flat string can be slowE.toUint8Array/E.toArrayBuffer
may also helpBut yeah, doing something like:
works fine