From: Doug Eleveld Newsgroups: comp.os.msdos.djgpp Subject: Re: RE: Style AND speed in C++? How? Please, I need some radical ideas on this one! Date: 22 Apr 1997 09:56:13 GMT Organization: Rijksuniversiteit Groningen Message-ID: <5ji1vt$51i@info.service.rug.nl> References: NNTP-Posting-Host: cmb17.med.rug.nl Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 60 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk I'm pretty sure that the overhead of a virtual function call could cause you some problems. It's OK to use virtual function for setup or 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. Your base video class can have an non-virtual inine function to call the correct function pointer. like this: // The pointer to the function void (*_putpixel)(const int x, const int y, const int color); class videoDriver { .... public: inline void putpixel(const int x, const int x, const int color) { _putpixel(x,y,color); } .... } // Here write the fastest putpixel for the S3 driver void S3putpixel (const int x, const int y, const int color) { } class S3videoDriver { .... public: S3videoDriver (...) { .... _putpixel = S3putpixel; .... } .... } This way you can't use more than 1 video card at a time, but I don't think this should be a problem. If you want maximum speed, don't check that _putpixel is null before you call it. Take as much code as absolutely possible out of the putpixel routine. Of course, always check the assembler output to make sure that the videoDriver::putpixel() is in reality inlined properly. If you have any other questions feel free to mail me, I'm no graphics guru but I find this sort of programming interesting... Doug Eleveld