Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!rutgers!njin!uupsi!sunic!lth.se!newsuser From: dag@control.lth.se (Dag Bruck) Newsgroups: comp.object Subject: Re: C++ vs. C Message-ID: <1991Apr27.122806.21434@lth.se> Date: 27 Apr 91 12:28:06 GMT References: <1991Apr24.125926.5146@asc.slb.com> <18905@crdgw1.crd.ge.com> <1991Apr25.213211.24114@asc.slb.com> <5111@dftsrv.gsfc.nasa.gov> Sender: newsuser@lth.se (LTH network news server) Organization: Department of Automatic Control, Lund, Sweden Lines: 32 In article <5111@dftsrv.gsfc.nasa.gov> njacobs@nssdcs.gsfc.nasa.gov writes: >In article <1991Apr25.213211.24114@asc.slb.com>, hargrove@asc.slb.com (Jim Hargrove) writes... > [long discussion of a specific example omitted. See original >posting.] > >>AND, I think the technical superiority of the C++ implementation is >>significant. It isn't so important when there are only 4 cases. But >>what if there are 20 or so? Then the savings in memory and execution >>may be really important. > >In this example (and most other cases) there is really no savings in >either memory or execution time. The visible switch is replaced by >invisible (compiler-generated) selection code which decides which >class the object belongs to. The code in the case statements is in >the methods for the individual classes. The virtual call of C++ is faster and requires less memory. 1. Only one "jumptable" is generated for each class, but you need one jumptable for every switch statement (typically). On the other hand, every object with virtual functions needs an extra word. 2. The virtual call is simpler than a switch and therefore faster. Empirical data was presented at one of the USENIX C++ conferences (1988 or 1989). >IMHO the important issue is ease of maintenance of the code. I completely agree. -- Dag