On Fri, Oct 5, 2012 at 8:59 AM, Jimb Esser <
wast...@gmail.com> wrote:
> Ah, yeah, it does now! We wrote our module back on node 0.4, which, I
> think, did not have typed arrays. That being said, it seems TypedArrays do
> not support un-aligned views (e.g. if you're reading a stream and want to
> read a F64 at byte offset 3, it throws an exception), as well they
> shouldn't, as that's not guaranteed to be efficient cross-platform, though
> is critical to performance in our specific situation. Also, it doesn't seem
> you can make a typed array view off of a Buffer (or get an ArrayBuffer off
> of a network read?), so that involves some copying, although since creating
> views is a native call and a bit expensive, we found it quickest to copy any
> network-received Buffer into one that already has views created anyway.
First-class support for ArrayBuffers and typed arrays in general is
something we want to add eventually (no fixed date though).
0.8.x supports creating typed arrays from Buffer objects:
var buf = new Buffer(16);
var arr = new Int32Array(buf, 4); // offset, defaults to 0
The buffer size and offset need to be multiples of the type size (4
for Int32Array, 8 for a Float64Array, etc.). The typed array is a view
of the buffer, i.e. it's zero-copy.