From node docs regarding creating typed arrays from buffers:
Buffer memory is interpreted as an array, not a byte array. What is, new Uint32Array(new Buffer([1,2,3,4])) creates a 4-element Uint32Array with elements [1,2,3,4] , not a Uint32Array with one element [0x1020304] or [0x4030201] .
This contrasts with simple javascript, where creating a typed representation of an array from ArrayBuffer uses ArrayBuffer memory as bytes (e.g. reinterpret_cast in C ++). I need this behavior in node when working with node buffers.
I could convert the buffer to an ArrayBuffer, but this is too slow for my application. (I tried a lot of methods - but they are all O (n) time.) (Edit: the fastest method I found is this , which is memmove op one and pretty fast, but still has at least short-term memory consumption until then until the reference to the source buffer is freed.)
Is there a way (fast / O (1)) to get a typed array from a buffer using the contents of the buffer as bytes instead of elements? (the required size of the array element is> 1 byte, of course.)
source share