[zeromq-dev] [PATCH] Custom zmq_msg_t allocator

Douglas Creager dcreager at dcreager.net
Wed Jan 19 17:51:58 CET 2011

This is a patch against the latest master, which allows you to provide a custom allocation function that ZMQ will use to allocate the internal buffers for zmq_msg_t objects.  I've got a multi-threaded ZMQ app that's passing millions of messages through inproc connections, and when I swap in glib's slice allocator, I see about a 25% increase in speed.  (The biggest win is that the standard Mac OS malloc() and free() need to lock a global mutex, while the slice allocator can work fairly independently in each thread.)

Note that the custom allocator doesn't affect how any other memory in the library is allocated; it only applies to zmq_msg_t instances.  My hunch is that most applications will need *many* more zmq_msg_t instances than contexts or sockets, though, so this is an okay tradeoff.

The patch also includes a new manpage for the new zmq_msg_set_allocator() function, which describes exactly when the zmq_msg_init_* functions will allocate heap memory.

Any comments or critiques?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Custom-zmq_msg_t-allocator.patch
Type: application/octet-stream
Size: 11374 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110119/86edf2fb/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110119/86edf2fb/attachment.sig>

More information about the zeromq-dev mailing list