delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/04/21:06:21

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: Quake vs. Demos
Message-ID: <Pine.SGI.3.91.970604104948.11241A-100000@atmosp.physics.utoronto.ca>
Nntp-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
Organization: University of Toronto - Dept. of Physics
In-Reply-To: <19970602.143604.7119.3.fwec@juno.com>
Date: Wed, 4 Jun 1997 14:57:52 GMT
References: <422564AA DOT 004D330F DOT 00 AT aks DOT com> <19970602 DOT 143604 DOT 7119 DOT 3 DOT fwec AT juno DOT com>
Lines: 37
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Mon, 2 Jun 1997, Mark T Logan wrote:

> 
> On Mon, 2 Jun 1997 16:29:29 +0200 eyal DOT ben-david AT aks DOT com writes:
> >I disagree on that also. Sometimes good OO design results in an even 
> >faster
> >code.
> >Think about  virtual function calls vs chains of "if-else" or "switch"
> >statements.
> 
> Not necessarily.  It doesn't matter how concise your source code is.  If
> the
> compiler implements virtual functions with a lot of conditional jumps,
> then it
> doesn't matter what you use.  Of course, I don't know how compilers
> implement
> virtual functions, so it may be that they are faster.  Anyone care to
> comment?

Compilers generally place a hidden function pointer in the class structure
for each virtual function.  Subclasses replace that function pointer with
one to their own definition of the virtual function, if the function has
been redefined. 

Therefore, calling a virtual function requires a single pointer
lookup/dereference no matter how many times the function has been
redefined in subclasses of subclasses.  Furthermore, the calling routine
never needs to be changed for a new subclass, whereas an if-else/switch
call would have to be changed in every calling function whenever a new
"subclass" is created.  Finally, with today's pipelined processors it
shouldn't be hard to convince yourself that a pointer lookup/dereference
can probably execute much faster than a conditional jump. 

---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019