Though it is possible to get correct UInt32Array
var a = new Uint32Array((new Uint8Array(new Buffer(16))).buffer);
a.length == 4
I found that it is much faster to use following trick
var
buffer = new Buffer(N),
dest = new Uint32Array(buffer.length>>2),
i = dest.length,o;
while(i--){
o = i<<2;
dest[i] = ((b[o]) |
(b[o + 1] << 8) |
(b[o + 2] << 16)) +
(b[o + 3] * 0x1000000);
}
What is strange - that using Uint8Array to copy data from Buffer to
ArrayBuffer in a loop is much slower.
2014-06-14 16:25 GMT+03:00 Denys Khanzhyiev <[email protected]>:
> Hello, I am in search of most efficient way to convert Buffer to
> ArrayBuffer.
> Can somebody explain this paragraph:
> "A Buffer object can also be used with typed arrays. The buffer object is
> cloned to an ArrayBuffer that is used as the backing store for the typed
> array. The memory of the buffer and the ArrayBuffer is not shared."
>
> from http://nodejs.org/api/buffer.html
>
> for me this means that I can do
>
> var ab = new Uint32Array(new Buffer(16));
>
> and get
> ab.length == 4;
>
> but this is not so
> ab.length is 16
>
> is it a bug? or I get that paragraph wrong?
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/CAP8%3DUyS0Z%2BmRtwfi6bCNjnGHCufk%3D3_c6mS47_jtgFEVTz9pMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.