Many Globals
Blitz3D Forums/Blitz3D Programming/Many Globals
| ||
Hi, my game is getting a little silly in the way of too many global variables, Will having a load of Globals adversly affect my CPU? |
| ||
Nope! But a small tip is to have all your global variables in a type, that way you avoid problems with mistyped variable names :) |
| ||
how would i do that?type gfx_id field gfx_menu1 = 1 field .... end type ? llike this? |
| ||
Something like this:type myglobals field var1 field var2 etc... end type global globs.myglobals = new myglobals globs\var1 = whatever globs\var2 = whatever etc. And then just access them using "globs\variablename" throughout the code. |
| ||
I use this technique all the time. VERY helpful and cuts down on coding errors. |
| ||
Interesting technique, I may try this |
| ||
Awsome, it works!!! looks a little better, and my computer seems to run faster :o\ |
| ||
Are You sure its faster? I've done a little test and its seems to me that globals ( and constants) are 100% faster... Buts its indeed handy to track typos! |
| ||
You could probably do a find and replace to convert the type fields back to proper globals for the release version. FYI: I vaguely remember that someone found that there was a limit to the number of globals that could be used in a program, but I believe the number that they were using was some ridiculously large amount. |
| ||
I would warn to be careful using lots of Globals (to include Global Custom Types) if at all possible. I ran into some bugs that were painfully difficult to find due to overwritting global data. In fact the bugs, were so painful that scrap weeks of work to start over:( |