Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2002-01-04 20:49:03


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


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