Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!news From: zweig@brutus.cs.uiuc.edu (Johnny Zweig) Newsgroups: comp.lang.c++ Subject: Re: The price of inheritance? Message-ID: <1989Sep11.002541.13902@brutus.cs.uiuc.edu> Date: 11 Sep 89 00:25:41 GMT References: <12581@brunix.UUCP> Sender: news@brutus.cs.uiuc.edu Organization: U of Illinois, CS Dept., Systems Research Group Lines: 20 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? >For example, let's say I create: > [a class with a virtual function that gets redefined in a subclass...] > [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. -Johnny