Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-04 21:07:57


----- Original Message -----
From: "Karl Nelson" <kenelson_at_[hidden]>
To: <boost_at_[hidden]>
Cc: <kenelson_at_[hidden]>
Sent: Friday, January 04, 2002 8:49 PM
Subject: Re: [boost] Loki SmartPtr study: Policy orthogonality issues

>
> Random interjection.
>
>
> > This kind of hierarchy has its benefits. On MSVC 7b2, this E:
> >
> > struct A {};
> > struct B {};
> > struct C {};
> > struct D { void * p; };
> > struct E: A, B, C, D {};
> >
> > has a size of 8, whereas this E:
> >
> > struct A {};
> > struct B: A {};
> > struct C: B {};
> > struct D: C { void * p; };
> > struct E: D {};
> >
> > has a size of 4.
>
> I should note on gcc the above test give very different results. Since
> a "struct A{};" must have a size > 0 and combining on struct with another
> must be on a word boundary (x86), the size of E would be 4+sizeof(void*)
in
> the second case and could be as high as 3*4+sizeof(void*) in the first
> (depending on the order of the inheritance.)
>
> This is kind of a good reason to avoid empty base classes like
> "struct A: public not_newable" as some compilers will cause those
> classes to become larger than expected, especially when it is for
> something like a ptr class where a large number may be declared.

Karl,

Which version of GCC are you testing with? GCC 3.0.x uses an aggressive
algorithm which optimizes away storage for empty bases whenever possible.

-Dave


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