[zeromq-dev] reusing messages

Martin Sustrik sustrik at 250bpm.com
Mon Jan 10 15:58:08 CET 2011


> 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 

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.


More information about the zeromq-dev mailing list