Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!princeton!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.arch Subject: Re: Do every object based systems suffer from poor performance ? Message-ID: <6894@alice.UUCP> Date: Sat, 16-May-87 11:44:54 EDT Article-I.D.: alice.6894 Posted: Sat May 16 11:44:54 1987 Date-Received: Sun, 17-May-87 02:55:49 EDT References: <6055@shemp.UCLA.EDU> <1831@hplabsc.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 59 Keywords: capability, object, 80286, 432 In article <1831@hplabsc.UUCP>, kempf@hplabsc.UUCP writes: > C++ can get full function call speed for nonvirtual > (noninherited) functions, or, for the cost of one level of indirection, > inherited functions can be used. and later writes: > and have dynamic lookup of methods at run time (which you can't do in > C++). Two small corrections. First, "virtual" != "inherited". If, for example, I say: class Foo { public: f(); }; class Bar: public Foo { public: g(); }; Foo foo; Bar bar; then calling foo.f(), bar.g(), and bar.f() all require the same amount of overhead, which is equal to an ordinary C function call. Second, C++ does have dynamic lookup of methods at run time -- that's what "virtual" is for: class Foo { public: virtual void print(); }; class Bar: public Foo { public: void print(); }; Foo foo; Bar bar; Foo* fp1; Foo* fp2; fp1 = &foo; fp2 = &bar; Now calling foo.print() and bar.print() still take the same overhead as a C function call, because the compiler can determine the type of foo and bar statically. Calling fp1->print() and fp2->print() involve dynamic lookup, because even though fp1 and fp2 are declared to be Foo pointers, they can really point to a Foo or anything derived from it. In this example, fp1->print() will call the Foo print function and fp2->print() would call the Bar print function. This dynamic lookup requires one extra memory reference per call.