www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/23/11:30:50

From: Doug Eleveld <D DOT J DOT Eleveld AT anest DOT azg DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: RE: Style AND speed in C++? How? Please, I need some radical ideas on this one!
Date: 23 Apr 1997 12:34:11 GMT
Organization: Rijksuniversiteit Groningen
Message-ID: <5jkvk3$m2v@info.service.rug.nl>
References: <861717941.0523452.0@[194.129.18.166]>
NNTP-Posting-Host: cmb22.med.rug.nl
Mime-Version: 1.0
Lines: 43
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


>Doug Eleveld writes:
>>I'm pretty sure that the overhead of a virtual function call could >>cause
>>something but don't use it for putpixel or linedraw.  The fastest and
>>neatest way that I can think of is to keep function pointers for all >>the
>>fast drawing functions, and fill them in in the constructor of whatever
>>video card.

>Shawn Hargreaves wrote back:
>You seem to be missing the point here: virtual functions _are_ function
>pointers! That's all the virtual keyword means: it just tells the C++
>compiler to allocate some space in the structure, fill it in with a >pointer
>to the code, and use this pointer whenever you call the function rather
>than branching directly to it. That's exactly the same thing as using
>function pointers directly in C, as I did in Allegro, but easier because
>most of the hassle is taken care of by the compiler...

Ohhh.... _thats_ how that works.  Thanks Shawn.  Is it possible to speed 
up that putpixel function without using virtual function calls _or_ 
function pointers?  

Do compiled sprites also use pointers to get to the correct code or do 
they just jump into the compiled sprite and execute from there. (I'll 
Check Allegro's source code later today to see exactly how they work.) 

Could you make some space for a global putpixel function and them copy 
the machine code for the specifc video driver putpixel onto that 
position?  You'd have to make sure that there is enough room, and there 
would be a little memory wastage but that shouldn't be too much of a 
problem. Could there be problems with offsets?

This leads me to a similar question about calling member functions.  Is 
it faster to call a member function through the object itself or through 
a pointer.  I (think) references are just glorified pointers so calling 
from a reference should be just as fast as with a pointer.  I guess I 
should test this myself by compiling some stuff and looking at the 
assembly output.  I'll try to do this tonight but if anybody knows the 
right answer tell me, because I could be testing it wrong...

Doug Eleveld



- Raw text -


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