Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: Messaging overhead Message-ID: <6590103@hplsla.HP.COM> Date: 20 Apr 89 17:30:42 GMT References: <1357@stl.stc.co.uk> Organization: HP Lake Stevens, WA Lines: 67 > C++ does `messaging' by calling virtual functions. > Calling a virtual function in C++ is only a little > slower than calling an ordinary member function. Hm, I guess I'd like to argue a little this definition of "messaging" as applied to C++. I'd like to claim that whenever I use a construct similar to: myObject.aMessage(withParams); -- or -- myObjectP->aMessage(withParams); -- then I've sent a message to an object in C++, regardless of the code that actually gets generated to perform this task. [Why should I, the class user, care how the class writer, or the compiler conspire to make this message happen -- as long as its damned fast!?] C++ gives the writer of the class that myObject belongs to several choices on how the request for a message to be sent to an object gets turned into code to do the job. Depending on what needs to be done, the "messaging" request may compile into: X times faster an indirect function call 10-100 a function call 5-50 inline code [example: a simple assignment] 100-1000 nothing infinitely -- where the "X times faster" column is intended to give a rough feel of the decimal order of magnitude times faster C++ is for this coding of a "message" verses what might be expected from other OOP languages that use hashed look-up schemes. Perhaps, most importantly are C++'s advantages in the last two cases. Frequently in OOP a message request simply sets or returns a simple value from inside an object: [myComplexNumber imagPart: 0.0]; or double imag = [myComplexNumber imagPart]; Using inline functions in C++, these simple "assignment"-type methods which are so common in OOP get turned into the same code as for C simple assignments: myComplexNumber.im = 0.0; or double imag = myComplexNumber.im; Finally, a good optimizing back end code generator may well discover that the inline code that is generated serves no useful purpose, and so removes it. Thus sometimes, no code whatsoever need be generated in the implementation of a C++ messaging request. Clearly, you cannot expect these levels of optimization in other OOPLs.