Many Globals

Blitz3D Forums/Blitz3D Programming/Many Globals

Neochrome(Posted 2004) [#1]
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?


fredborg(Posted 2004) [#2]
Nope!

But a small tip is to have all your global variables in a type, that way you avoid problems with mistyped variable names :)


Neochrome(Posted 2004) [#3]
how would i do that?

type gfx_id
 field gfx_menu1 = 1
 field ....
end type

? llike this?


fredborg(Posted 2004) [#4]
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.


Warren(Posted 2004) [#5]
I use this technique all the time. VERY helpful and cuts down on coding errors.


Rob(Posted 2004) [#6]
Interesting technique, I may try this


Neochrome(Posted 2004) [#7]
Awsome, it works!!! looks a little better, and my computer seems to run faster :o\


Abomination(Posted 2004) [#8]
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!


Zethrax(Posted 2004) [#9]
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.


Techlord(Posted 2004) [#10]
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:(