[zeromq-dev] [PATCH] Custom zmq_msg_t allocator
Martin Sustrik
sustrik at 250bpm.com
Thu Jan 20 00:12:31 CET 2011
Hi Douglas,
> 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.)
Why not use the existing zmq_msg_init_data() function to get the desired
functionality? It allows you to wrap pre-allocated buffer into a
message. It also allows you to specify the deallocation function.
So using the custom allocator would look something like this:
void *buff = my_alloc (1000);
...
zmq_msg_t msg;
zmq_msg_init_data (buff, 1000, my_free);
...
Martin
More information about the zeromq-dev
mailing list