-
Wed 2019.08.14
Have you considered for memory efficiency @indianajones using a clamped array?
In #2 @maze1980 points out the
set()
function which is the way I do this task. Access can even be sped up with 'inlineC', but really won't be needed for your project needs. Grasping the hierarchy took me a bit, as the above is inherited from ArrayBufferView. Uint8ClampedArray is a type of TypedArray from which the set method is defined.Also check out heading 'STRINGS VS. FLAT STRINGS' from link in #2 above.
For your 'light' reading pleasure ;-)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray#Methods
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
I have a connection to a device that's sending binary data over a TCP connection, and of course I get the data in chunks, which must be concatenated as new data comes in. Because the data I receive is binary, I have to convert the incoming data using E.toUint8Array, which works great. But when new data comes in, I have to add the new data to the existing Uint8Array, and I'm struggling to find the right way to do this. Anyone have experience with this?