To: ma6djh AT bath DOT ac DOT uk Cc: djgpp AT delorie DOT com Subject: Re: Style AND speed in C++? How? Please, I need some radical ideas on this one! Message-ID: <19970430.204530.7119.0.fwec@juno.com> References: From: fwec AT juno DOT com (Mark T Logan) Date: Wed, 30 Apr 1997 20:46:36 EDT Precedence: bulk On Sat, 26 Apr 1997 18:28:20 GMT ma6djh AT bath DOT ac DOT uk (D J Hampson) writes: >> 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 way I was going to do it was to have a screen mode class for whatever >mode I'm in (just 320x200x256 to start with), with three private buffers >(for triple-buffering), but a public reference to the current buffer to >draw in. So it's just as quick as the best C equivalent for putpixel and >getpixel, and I can write seperately whatever line drawing routine I >want, but I can switch modes (VESA or whatever when I find out how it all >works!) completely independantly of the rest. that is part of what c++ is about, being able to switch modes, and keep that code *totally* independent of the rest of the program. However, C++ is also about protecting your data members. If you wish to program with true C++ class (pun intended), you cannot have any public data members. (Question for the gurus: Is there any situation where this is not the case?). The reason for this is that when you have a class, the only thing that can touch the variables inside the class are the class's member funtions. This is advantageous (did I spell that right?) because when a variable somehow comes to have a bogus value inside of it, you know for a fact the class itself is at fault. Now you know where to begin debugging. And knowing is half the battle :-) >The screen mode class will do all the stuff like set up the screen >interrupt code and find the most recently draw screen to chuck on >0xa0000. If you want to make the code portable, you should isolate the hardware specific stuff from the program code. In other words, have a screen class, but have the class call functions for setting the screen mode. These functions contain *all* of the hardware specific stuff, and are in their own seperate file(s). Then when you want to port the program, you have a couple of isolated files to rewrite, instead of a whole program. Good luck, || fwec AT juno DOT com || || - Watch Gary Kasporov vs. Deep Blue at www.chess.ibm.com - || || Disclaimer: This is not an ad for ibm.