Path: utzoo!attcan!uunet!brunix!gjb From: gjb@cs.brown.edu Newsgroups: comp.lang.c++ Subject: The price of inheritance? Message-ID: <12581@brunix.UUCP> Date: 12 Aug 89 20:52:51 GMT Sender: news@brunix.UUCP Reply-To: gjb@cs.brown.edu () Organization: Brown University Department of Computer Science Lines: 41 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: class A { public: virtual void Method(); void Another_Method(); }; class B : public A { public: virtual void Method(); }; class C : public B { public: virtual void Method(); } I realize that calling A::Method() will be more expensive than calling A::Another_Method(). But is calling B::Method() slower than A::Method()? And will calling C::Method() be slower still? If so, how much slower? Twice as slow as B::Method()? Three times as slow as A::Method()? Of course, I'm only speaking of the overhead involved in calling the functions -- not the time complexity of the function itself. Could someone explain how this works? Does anyone have statistics? I'd love to know. Thanks in advance. -Greg +----------------------------------------------------+ Greg Brail Work: (401)863-7692 Internet: gjb@cs.brown.edu BITNET: gjb@browncs.bitnet UUCP: ..uunet!brunix!gjb Home: (401)831-3736