|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-02-11 11:07:43
David Abrahams wrote:
[...]
> OK, so what you really want is alignment_of<boost::detail::max_align>.
Ah, there it is. Unions are great for this.
> By "STL" I presume you mean your particular STL implementation.
No I meant SGI's Standard Template Library (__STL_DATA_ALIGNMENT in
pthread_alloc).
[...]
>> Ex.:
>>
>> - The processor aligns each character to 8 bits.
>> - The processor aligns each integer to 32 bits.
>>
>> 0x8000 character
>> 0x8001 padding
>> 0x8002 padding
>> 0x8003 padding
>> 0x8004 integer
>> 0x8005 integer
>> 0x8006 integer
>> 0x8007 integer
>
> template <class T>
> struct padding_of
> {
> BOOST_STATIC_CONSTANT(
> std::size_t, value = alignment_of<max_align>::value
> - sizeof(T) % alignment_of<T>::value
> );
> };
>
> or, if you don't trust max_align, then:
>
> template <class T>
> struct padding_of
> {
> BOOST_STATIC_CONSTANT(
> std::size_t, value = alignment_of<max_align>::value
> % (sizeof(T) % alignment_of<T>::value)
> );
> };
Thanks!
Philippe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk