4 ms·
they are pure js, though streams in node emit Buffer objects which can be mostly emulated using html5 Int32Arrays
by maxogden 14y ago
they are pure js, though streams in node emit Buffer objects which can be mostly emulated using html5 Int32Arrays
- tantalor 14y agoHad to look that up, > A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. http://nodejs.org/docs/v0.3.1/api/buffers.html http://nodejs.org/docs/v0.3.1/api/buffers.html Are streams limited to binary buffers, or may they also emit JavaScript objects or primitives? Binary may be great for low-level I/O streams, but I'd expect more nuanced events for high-level streams.
- maxogden 14y agoYou can emit anything but it just so happens that 99% of the streams used in node core are Buffers for performance reasons (Buffers are allocated outside of V8's heap). An example of emitting objects is in here https://github.com/maxogden/dominode/blob/master/example.html https://github.com/maxogden/dominode/blob/master/example.htm...
- mjor 14y agoNode.js Buffers are actually built on top of V8's Uint8Array. Using 32-bit integers to represent 8-bit values seems quite wasteful.
- tantalor 14y agoSource please? The docs say a Buffer is "outside the V8 heap".
- mjor 14y agoYes, the chunk of memory is managed by node, but each Buffer instance is linked with a slice of the heap through `v8::Object->SetIndexedPropertiesToExternalArrayData()`, the same way a JS `Uint8Array` would. Here's the relevant link: https://github.com/joyent/node/blob/master/src/node_buffer.cc#L707 https://github.com/joyent/node/blob/master/src/node_buffer.c....