Path: utzoo!attcan!utgpu!watmath!watdragon!dvadura From: dvadura@watdragon.waterloo.edu (Dennis Vadura) Newsgroups: comp.lang.c++ Subject: Re: Efficiency of C++ relative to C?? Message-ID: <16557@watdragon.waterloo.edu> Date: 21 Sep 89 15:00:53 GMT References: <16493@watdragon.waterloo.edu> <9924@alice.UUCP> Reply-To: dvadura@watdragon.waterloo.edu (Dennis Vadura) Organization: Computer Science Dept., University of Waterloo Lines: 53 In article <9924@alice.UUCP> shopiro@alice.UUCP (Jonathan Shopiro) writes: >In article <16493@watdragon.waterloo.edu>, dvadura@watdragon.waterloo.edu (Dennis Vadura) writes: >> questions deleted... >> >Yes, virtual functions are more expensive than ordinary functions >(about 4 or 5 more memory references per call), but you don't have to >use virtual functions if they aren't needed. >... >In your question you assume ``the full power of C++.'' Clearly if you >use every feature wherever it could fit (for example, make every >function and base class virtual), you could take a performance hit, Yes but..., The original motivation for my question was from the standpoint of using a lot of general classes in my implementation (although I didn't say that). In this case if the class designer was opting for maximum flexibility, generality and reusability then it is my feeling they end up using virtual functions a lot. Not only that, but it is my understanding that you end up designing a lot of classes to use virtual inheritance so that if you inherit a class twice you only get a single copy of the class. I'm not completely clear on this as yet, but this appears to incur further costs. >always have written the same program in assembler. That is to say, if >you're considering higher level languages at all, performance is not >your only criterion, you're also concerned about programmer productivity. I agree whole heartedly. Infact I have a language in mind where almost all expressions translate into function invocations and the implementation mechanism forces these to be indirect references through a pointer. The implementation takes a pretty severe hit on performance, but the great expressive power of the language outweighs this somewhat. That is why I am curious how much of a performace hit people are willing to live with. >programming large applications is too expensive, then try C++. You >will be able to build more complicated applications than you could >before, and, if you program carefully, you will not incur any >performance penalty. Sorry I disagree. Theorem: I can write in C anything I write in C++, it might just take longer. Proof: cfront generates C as output. I can type it in :-) -dennis -- -------------------------------------------------------------------------------- The only happy people are Single MEN |Dennis UUCP,BITNET: dvadura@water and Married WOMEN. |Vadura EDU,CDN,CSNET: dvadura@waterloo ================================================================================