[zeromq-dev] Memory alignment

Martin Sustrik sustrik at 250bpm.com
Fri Jul 8 08:48:54 CEST 2011


Hi Emmanuel,

> Do you confirm my understanding of this problem?
> If yes, how is it possible to send small message which will be received
> aligned in a 4 bytes boundary?

This can't be done in a generic way. When sending messages initialised 
using zmq_msg_init_data() via inproc, you get the same buffer that was 
sent by the sender. I.e. if the sender aligned the buffer in a special 
way, that's what you'll get.

In general, it's advisable to parse the messages in 
alignment-independent manner. 0MQ itself does so for its internal data, 
see src/wire.hpp. That'll make your application more portable.

However, if this is considered an useful optimisation. zmq_msg_t (or 
rather it's equivalent in 3.0) could be restructured in such a way that 
the buffer is located at the beginning of the structure. That way it 
will be aligned in the same way the structures are (see c specs). Note 
though, that this will not be a trivial exercise as you are going to 
mess with compiler's standard way of aligning structure members for 
which there is no standard means in the language.

Martin



More information about the zeromq-dev mailing list