Virtual base alignment

Mark Mitchell mark at codesourcery.com
Mon Jan 3 06:12:58 UTC 2000


I think the current proposal for allocating virtual bases is still a
little suboptimal.  In particular, given:

  struct A { void f(); };
  struct B : virtual public A {};
  struct C : virtual public A, virtual public B {};

we'll give `C' a larger size than for:

  struct C : virtual public B, virtual public A {};

where we'll reuse the `A' part of `B' rather than reallocating it.
  
I know that ordering can already affect size (principally because of
alignment issues) but I think that in this case we might as well not
punish programmers for choosing the "wrong" ordering.

I think we should change the green A-17 proposed resolution to
indicate that if one of the virtual bases is a (direct or indirect)
primary base of one of the other virtual bases then we need not
allocate a fresh copy.

FWIW, it turns out to actually be easier in GCC to code the more
generous version.

The algorithm to do this is linear in the size of the hierarchy: just
iterate through the inheritance DAG marking all primary bases.  Any
virtual base classes that remain unmarked need to be allocated in step
III.  A slight formalization of this sentence might be a good way to
express which bases to choose for III.

--
Mark Mitchell                   mark at codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com




More information about the cxx-abi-dev mailing list