Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-03-01 11:37:35


Thinking a little further, I think what we want is this:

take the union of all types whose alignment is <= that of the target
if the alignment is not a multiple of the target alignment,
    take the union of all types whose size is <= that of the target
    if the alignment is not a multiple of the target alignment,
        take the union of all the types and cross fingers
assert success.

The intent of this approach is to find a minimally-aligned type which
ensures alignment of the target while maintaining compatibility with brian's
basic strategy.

It seems like anything more simple-minded will either over- or under-align
in more cases. Over-alignment is wasteful, and under-alignment is dangerous.

-Dave

----- Original Message -----
From: "Fernando Cacciola" <fcacciola_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, March 01, 2002 11:01 AM
Subject: Re: [boost] Re: New version of valunion and stack_allocator
uploaded

>
> ----- Original Message -----
> From: "Douglas Gregor" <gregod_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Friday, March 01, 2002 12:31 PM
> Subject: Re: [boost] Re: New version of valunion and stack_allocator
> uploaded
>
>
> > On Friday 01 March 2002 10:16 am, you wrote:
> > > > template<typename T, size_t sz, size_t align>
> > > > struct member {
> > > > typedef typename ct_if<sizeof(T) <= sz && sizeof(U) <=
> align,
> > >
> > > What is 'U'?
> >
> > My typo :(. It was supposed to be T.
> >
> > > > T,
> > > > char>::type type;
> > > > };
> > > >
> > > > template<size_t sz, size_t align>
> > > > union force_align {
> > >
> > > What are 'sz' and 'align'?
> >
> > The size and alignment of the type for which we want an alignment type.
> E.g.,
> > if we need to create aligned storage for std::string, we could use:
> >
> > union std_string_raw_storage {
> > force_align<sizeof(std::string),
alignment_of<std::string>::value>::type
> > align1;
> >
> > char buffer[sizeof(std::string)];
> > };
> >
> In the files section, there is a header
>
>
http://groups.yahoo.com/group/boost/files/class_optional/aligned_storage.hpp
>
> which provides a convenient interface (IMO) for this feature.
> I believe it combines perfectly with Brian's force_align<> and
> alignment_of<>
> (it just adds a high-level user-friendly interface)
>
> BTW, latest Brian's sources are in:
>
> http://groups.yahoo.com/group/boost/files/align_of_to_boost.zip
>
> Additionally, I haven't yet read it, but it would be relevant to look at
the
> recent Andrei's expert column:
>
> Generic<Programming>: Discriminated Unions (I)
> http://www.cuj.com/experts/2004/alexandr.htm
>
>
>
> Fernando Cacciola
> Sierra s.r.l.
> fcacciola_at_[hidden]
> www.gosierra.com
>
>
>
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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