From the node docs regarding the creation of typed arrays from Buffers:
The buffer's memory is interpreted as an array, not a byte array. That
is,creates a 4-element
new Uint32Array(new Buffer([1,2,3,4]))
Uint32Array, not an
[1,2,3,4]with a single
As far as I know, it is not possible to do this without making a copy of the data in memory.
Even your example
new Uint32Array(new Buffer([1,2,3,4])) internally does this (meaning it's not O(1)).
Note that typed arrays are just views of an
Buffer, that's not possible).
new Uint32Array(array) creates an
4 * array.length bytes. You can access it with
uint32Array.buffer. The constructor treats your
Buffer no different than a normal
The best solution I know is the one you already found.