On Mon, Nov 18, 2013 at 9:56 PM, Aaron Boxer <[email protected]> wrote:
> is it possible to use a fixed buffer for reads, instead of alloc being
> called for each read?
>
> So, say I specify a 65532 byte buffer, can I tell libuv to use this buffer
> repeatedly, and if there is more data than can fit, to just call the
> callback again?
>
> Thanks,
> Aaron

That works on Unices (though it's best considered an implementation
detail) and will usually work on Windows.  uv-win uses native
completion-based I/O, which means it's possible for allocation
lifetimes to overlap.

In node.js, we exploited* the 'mostly non-overlapping' fact by having
a slab allocator that uses bump allocation.  If buf->base + buf->len
== slab->top in the read callback, then it's safe to release the
memory with slab->top -= buf->len.  If the bump pointer has moved,
then leave it to the garbage collector to reclaim the memory.

More advanced schemes are certainly possible but the slab allocator
had the advantages of being easy to understand and fast in the common
case.

* We now use something else but not because of issues with the slab allocator.

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" 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].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to