Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2007-11-14 04:52:13


Lubomir Bourdev wrote:
> John Maddock wrote:
>> So... it's a data alignment error: I wonder are you trying to write
>> to
> an
>> integer on a char boundary or something?
>
> John, thanks for your help.
> I believe this is indeed the problem. GIL needs to read/write a type
> bigger than a byte that starts at a char* address, so it is possibly
> not aligned.
>
> One approach is to special-case platforms which cannot dereference at
> a non-byte boundary (I couldn't find a config flag that detects this,
> anyone?) and provide a special solution for such platforms. The
> solution
> I imagine will involve static recursion that reads/writes each byte
> and shifts it in place.
> Is there such a code in Boost? My search resulted only in references
> to
> a "Boost.Endian" proposal by Darin Adler / Beman Dawes but I couldn't
> find the code and I don't know if it has a solution to the above
> problem.

No I don't believe we have any such code or a config macro: one of the
problems I believe is that whether or not the code will trigger a hardware
signal may depend upon whether certain hardware flags are set or not: for
example but I seem to remember that even Intel hardware can signal on
unaligned access if the right flag is set :-(

You could use memcpy, or std::copy to copy the bytes I guess, but that
doesn't seem all that efficient? Or it shouldn't be too hard to roll your
own "byte copier" for some type T?

Regards, John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk