[zeromq-dev] Memory alignment

Emmanuel TAUREL taurel at esrf.fr
Thu Jul 7 12:47:28 CEST 2011

Hello all,

I am using zeromq 2.1.7. I am using a multipart message sent from a PUB 
socket to some SUB sockets.
Then, once in the receiver process, the message is sent  to worker 
threads using some PUSH/PULL sockets and a zmq queue device to link the 
SUB and the PUSH socket.
My message has 6 parts. Part 1 and 2 are classical strings, part 3 is 
simply 4 bytes and part 4, 5 and 6 are encoded buffer.
I am using the C++ binding. Transmission between PUB and SUB works fine.
However, for subscriber running on the same host than the publisher, the 
message part 4 that I retrieve in the worker thread using a
zmq::message_t object is returned to me in a buffer aligned in memory in 
a 2 bytes border (address 0xXXX2 and not 0xXXX0 or 0xXXX4).
I am using the zmq::message_t::data() method to retrieve the memory buffer.
This behavior disturbs the software which decodes this buffer because it 
assume that the buffer is aligned on a 4 bytes border.

Is there any rule concerning buffer memory alignment within zmq?
Is there something I can do to retrieve my buffer aligned on a 4 bytes 

Thank's for your answers


Emmanuel Taurel

More information about the zeromq-dev mailing list