[zeromq-dev] ØMQ VSM data alignment
jon at totient.co.uk
Wed Aug 4 20:19:03 CEST 2010
Matt Weinstein wrote:
> On Aug 4, 2010, at 1:37 PM, Andrew Hume wrote:
>> this sort of thing can get problematic quickly.
>> the combinatorial explosion of cache-line design, memory design,
>> language alignment rules, architectures allowing non-aligned references
>> (but punishing you with slowness) makes testing hard.
>> on the other hand, starting on a 8 byte boundary is always a good
>> idea in modern architectures.
>> better style is to use a byte stream so you won't get bitten by
>> LSB/MSB issues
>> or packets coming from other machine architectures.
> Yes, but I want to do this:
> zmq::message_t foo;
> my_struct const* pstruct = reinterpret_cast<my_struct
> cout << "Works like magic: " << pstruct->member << ". All your
> processor are belong to Intel! (*)" << endl;
> That's the no-copy approach :-)
> I can do it with malloc() without issue or penalty...
> (*) There are no other architectures :-)
I havent ever tried, but does this not work?
zmq::message_t foo(&ms, sizeof(my_struct), NULL, NULL);
// now i think here you would have to to check the size was sizeof
my_struct. and the data() is indeed the address of ms.
More information about the zeromq-dev