Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!turk
From: turk@Apple.COM (Ken "Turk" Turkowski)
Newsgroups: comp.lang.c++
Subject: Re: The price of inheritance?
Message-ID: <4522@internal.Apple.COM>
Date: 3 Oct 89 08:12:53 GMT
References: <12581@brunix.UUCP> <1989Sep11.002541.13902@brutus.cs.uiuc.edu>
Organization: Advanced Technology Graphics, Apple Computer, Cupertino, CA, USA
Lines: 28

In article <1989Sep11.002541.13902@brutus.cs.uiuc.edu> zweig@brutus.cs.uiuc.edu (Johnny Zweig) writes:
>gjb@cs.brown.edu writes:
>
>>Some recent work I've been doing with C++ and the InterViews
>>user-interface toolkit has made me wonder how expensive inheritance
>>is. I realize that a virtual function is slower than a non-virtual,
>>but does the depth of the class hierarchy affect speed?
>> [Will the subclass's virtual function be more expensive to call?]
>
>No. Virtual function tables are (as far as I know or can imagine)
>flattened -- each (subsubsub...)class just has a big list of pointers. In
>the example, the virtual function would just be the value of the nth
>(probably 0th) pointer in the v-table. Same banana in the subclass, or
>any other {sub}*classes.

Constructors, however, get slower and slower, even when there is no
constructor.  It's amazing how often I get the message:

	MyClass::MyClass() too complex for inlining.

when the class and all of its members are doing nothing during their
construction but returning.  The C code is littered with the address
of every object's constructor loaded into a register.
-- 
Ken Turkowski @ Apple Computer, Inc., Cupertino, CA
Internet: turk@apple.com
Applelink: TURKOWSKI1
UUCP: sun!apple!turk