[nanomsg] Re: why memcpy data to be sent?

  • From: Paul Colomiets <paul@xxxxxxxxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Mon, 27 Oct 2014 23:21:28 +0200

Hi Jack,

On Mon, Oct 27, 2014 at 9:08 PM, Jack Dunaway <jack@xxxxxxxxxxxxxxxx> wrote:
> One proposal is to add a new flag to nn_sendmsg() in the spirit of the
> "SQLITE_TRANSIENT" flag when inserting data into a sqlite database
> (https://www.sqlite.org/capi3ref.html#sqlite3_bind_blob), iff the binding is
> willing to guarantee the burden of ensuring that memory location remains
> immutable for the duration of the call.
>

Well, actually data is always assumed to be immutable *during the
call* to nn_sendmsg. What we are discussing here is what happens
afterwards.

What can be optimized is copying data when there are enough OS buffers
available. In fact currently message is copied and deallocated
immediately during nn_sendmsg call if message fits TCP buffer. This
case can be optimized to no allocation and no copy. So unless you
sending very large messages or have improperly tuned buffers, you
should get no copy.

I'm not sure how complex such optimization would be. And what is the
right time to do it.

-- 
Paul

Other related posts: