[zeromq-dev] reusing messages

Andrew Hume andrew at research.att.com
Mon Jan 10 16:08:06 CET 2011


thanks, martin.
just to be sure, though, will zeromq handle the contents correctly
when it provided them? as in

zmq_recv(isock, &msg, 0)
zmq_msg_copy(&msg1, &msg);
zmq_send(sock1, &msg);
zmq_send(sock2, &msg1);
zmq_msg_close(&msg);
zmq_msg_close(&msg1);

(i can look after my own data, but this is done by the library.)

On Jan 10, 2011, at 7:58 AM, Martin Sustrik wrote:

> Andrew,
> 
>> is it okay to reuse messages? such as in
> 
>> zmq_send(sock1, &msg);
>> zmq_send(sock2, &msg);
>> zmq_send(sock3, &msg);
>> zmq_msg_close(&msg);
> 
> 0MQ is doing zero-copy, meaning that msg's buffer is passed down the stack to be sent to the network. Thus, after sending the message first time msg will be empty and the empty message will be sent to sock2 and sock3.
> 
> What you need to do is use zmq_msg_copy() function to create 3 messages. These, however, will reference a single buffer, so no worry abour copying the data.
> 
> Martin

------------------
Andrew Hume  (best -> Telework) +1 623-551-2845
andrew at research.att.com  (Work) +1 none currently
AT&T Labs - Research; member of USENIX and LOPSA




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110110/dcfa7826/attachment.htm>


More information about the zeromq-dev mailing list