Zero copying with ZeroMQ

I have been looking at the ZeroMQ zero copy pages for a project. I’ve dipped in and out of ZeroMQ over the last few months but am looking at it in a different light. I’ve been building some toy applications with it to greater or lesser success, such as File transfer system, and so on.

I thought I would look at the zero-copy functions to reduce memory during the transfer.

TheĀ  blog post had the code:


zmq_msg_t msg;
void *hint = NULL;
zmq_msg_init_data (&msg, buffer, 1000000, my_free, hint);
zmq_send (s, &msg, 0);

Having been used to using zmq_send(), I kept getting an error:

zmq.h:354:1: note: ‘zmq_send’ declared here
ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags);

A little digging around the ZeroMQ API brought me back to the zmq_msg_send() page which does allow for some similar code to be used for zero-copy messages.


zmq_msg_t msg;
void *hint = NULL;
zmq_msg_init_data (&msg, buffer, 1000000, my_free, hint);
zmq_msg_send (s, &msg, 0);

It might just be an old page which is pointing to the ZeroMQ 2.x release (I’m using 3 on box and some where else I have 4.x) but thought that I would make a note. Looking at the API, 4 does not appear to have changed anything in that respect but I should probably look at the Curve security options.

Given the size of data that I’ve been using to test this with, I’ve not seen much improvement but I will be moving towards some more production style data shortly to see whether this makes a difference at all.