[zeromq-dev] clarification regarding zero copy
Erdos
covariantmonkey at gmail.com
Thu May 9 02:50:09 CEST 2013
Hi,
I have a short bit of code to send data over a push socket via the
zero-copy mechanism:
static void respawn(void* data, void* hint){};
int main ()
{
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_PUSH);
socket.connect ("tcp://localhost:5555");
string payload = "";
for (int request_nbr = 0; request_nbr != 10000; request_nbr++) {
payload = "boo";
zmq::message_t request ((void *)payload.data(), payload.size(),
respawn); //L1
socket.send (request, ZMQ_NOBLOCK); //L2
}
return 0;
}
Its not entirely clear to me if I can safely assume that the buffer
'payload' is available to me immediately following the 'send' operation
(L2).
Does the 'send' internally copy the contents of payload on to something?
You can see why if for some odd reason the contents are not immediately
dealt with (i.e. zmq is still waiting to do something with payload buffer),
then assigning new values to payload at the top of the loop is just wrong.
The code block above runs just fine but I would like to be sure-- are there
any mechanism for zmq to signal that it has finished dealing with payload
buffer and okay for me to re-assign it?
Many thanks
Asif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130508/5acad8ac/attachment.htm>
More information about the zeromq-dev
mailing list