Hi, I've been learning how to use the bit blt and associated API functions recently for some simple game programming and have finally hit a stumbling block that I can't seem to find any information on.
Originally, I had all my graphics related code (such as getting DCs, etc) in the Form_Load part of my program. After this getting really messy to edit, I decided to start using a module to separate out graphics related commands. All I did was copy and paste blocks of code from various parts into the module and only changed a few references (such as when I needed information about the size of something on the form and so on). Now, a process which used to take ~350 ms now takes ~2500 ms. I've gone through step by step and it's following the exact same logical process that it was before, but, for some reason, is taking a whole lot longer. Unfortunately, I have no clue why this is.
The variables I use within the module are declared as private for the entire module, as are the api functions. I removed all similar declarations from the form, so there isn't any sort of conflict there. There aren't any unnecessary calls, so that's not it.
If anyone can help explain this quirkiness, I'd certainly appreciate it. I'd hate to have to go back to being sloppy again.
01-14-2007, 06:37 AM
maybe in debug mode only ,not at real run-time ??
or maybe u have separeted portions of the code and put them in functions , so calling functions take much time than run them inline .. but if u have totally separeted complete functions maybe it's debug time problem only .
01-14-2007, 04:03 PM
One thing to note is that you don't have to put the functions in a seperate module. You can keep them in the forms module. Just because you broke the code up into functions does not mean that those functions have to be in a seperate module.
Next I have never heard of there being a speed difference between being in a module or in a forms module. As a test copy all of the code from the module to the bottom of the code in your forms module. Don't change anything just paste the code after the last line in the forms module, then remove the seperate module from the project and give it a run. Check to see if there is a time difference. I think you will find that there is no difference from being in a seperate module and being in the forms module. If I am correct then it has to do with the changes you made when you seperated the code into a seperate module. Start there and then report back what you find. At which point we can help you track down the slower code.
01-15-2007, 02:13 PM
Ron makes me remember one thing that in the form module functions should be "private" but in external module they must be public ... to be able to call them .. this is maybe which make the difference in time , to avoid this if your module has a function like "initGraphics" for example , and the rest of functions depend on this only so u may make this function only as public to call it from form module , and the rest of functions in the first module should be private as u don't need them externaly .
this may decrease your weasted time and if u care about the rest of this time u may make as Ron told u to put them all in the same form module by private method .
otherwise in most cases the class method make more efficient code -not after one test- but after long time of using your program .. and u should have it work well and fast .