[zeromq-dev] [PATCH] reduce memory allocations in yqueue
sustrik at 250bpm.com
Thu Feb 4 09:28:17 CET 2010
Steven McCoy wrote:
> On 3 February 2010 23:53, Joe Thornber <joe.thornber at gmail.com
> <mailto:joe.thornber at gmail.com>> wrote:
> It reduces memory allocation in yqueue by holding onto one unused
> chunk rather than handing it back to the global new/delete allocators.
> For the common case where messages are being produced at a similar
> rate to consumption this is a big win.
> Why would you do this instead of just doubling N, there already is one
> chunk in the container?
yqueue is not a cyclical buffer. Instead it allocates chunks on the
writer side and decallocates them on the reader side. Thus, however
large the chunk, it's still going to be allocated/deallocated every now
What Joe did is optimising the mechanism of handing the used chunks from
the reader thread back to the writer thread. Instead of free/malloc pair
single chunk can be moved using atomic ops. Interestingly, this
mechanism is used exclusively (i.e. no malloc/free altogether) when the
system is not fully loaded and messages are just passing through the queue.
More information about the zeromq-dev