As far as I know, the buffer won't be used by libuv/node after the write
callback is called, that's one of the purposes of this callback.  Someone
please correct me if I'm wrong.

On Thu, Apr 19, 2012 at 11:08 AM, Joran Greef <[email protected]> wrote:

> I need to write a few thousand 24 byte values to a TCP socket which
> represents a WebSocket connection.
>
> I must retrieve them individually from disk, but I want to group a
> thousand of them into each write, since the write represents a WebSocket
> message and each message has additional message header overhead.
>
> At first I was instantiating a 24 byte buffer for each value, reading into
> this from disk, iterating over the array of values, calculating the size,
> creating a large buffer, copying these into it, and then writing this
> aggregate buffer out to the socket. There were a few abstractions involved
> and this was the simplest code flow.
>
> I was concerned about the needless copying and did a rough benchmark, and
> creating a large buffer up front and writing directly into it is 3 times
> faster than creating many small buffers, then creating a large buffer and
> copying the small buffers.
>
> I would like to change tactics and create a buffer upfront, read the small
> values directly into this from disk, and then write this to the socket.
> After receiving the callback from the write (flushed to kernel buffers) I
> would like to start writing into the same buffer at index 0.
>
> Is it safe to modify a buffer after it has been flushed to the kernel
> buffer?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> 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 post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to