[zeromq-dev] ØMQ VSM data alignment

Jon Dyte 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;
>
>     s.recv(&foo);
>     my_struct const* pstruct = reinterpret_cast<my_struct 
> const*>(foo.data());
>
>     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?

    my_struct ms;
    zmq::message_t foo(&ms, sizeof(my_struct), NULL, NULL);
    s.recv(&foo);

    // 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.



Jon






More information about the zeromq-dev mailing list