Empty base optimization, sharing vptrs

Matt Austern austern at isolde.engr.sgi.com
Wed Jun 16 22:43:25 UTC 1999


On Jun 16,  3:30pm, Michael Ball wrote:

> I don't see how you can allocate more than one immediate polymorphic
> bases at offset 0, they will in general require different vtables since
> they will have different virtual functions.  If by empty you also
> imply that they have no virtual functions of their own, then OK, they
> can be ignored and only their bases matter.  Normally I would think
> that empty implied only a lack of data members.

Oops, yes.  You're quite right; only one empty-except-for-the-vptr
base class at offset 0, and that's true whether it's a non-virtual
base class with virtual functions, or a virtual base class.

Another goof I just noticed: if it's a virtual but nonpolymorphic
base class then we can't put it at offset 0, because the derived
class has a vptr at offset 0 and the base class doesn't.

> >(Oh, another point.  I don't have a proof, but my guess is that
> >finding an optimal space-minimizing solution to the class layout
> >problem is equivalent to the travelling salesman problem.  I'm not
> >going to try.  What I'm going to present tomorrow is a heuristic
> >that I think should usually do better than just declaration order.)
>
> I would need to see real numbers on real programs before I am convinced
> that such algorithms are other than bugs waiting to happen.

I don't know whether this sort of reordering is a good idea.  Part of this
exercise is to see if we can come up with a simple enough heuristic so that
it's even worth running tests.

			--Matt






More information about the cxx-abi-dev mailing list