What's Gonna Be My Penalty...
Blitz3D Forums/Blitz3D Programming/What's Gonna Be My Penalty...
| ||
... for using lots of Globals... performance wise, will it degrade my program significantly... i'm using global variable instances of TYPEs that carry a lot of fields... is this a good way to 'pack' all those globally accessible variables so that i don't get penalized, or does it really not matter at all... thanks --Mike |
| ||
I doubt it - even on a PC as slow as my old desktop this sort of issue has never been the bottleneck performance wise. |
| ||
I only use globals. and my types are always pre-defined by globals Global p.player Global e.enemy ; you get the point |
| ||
I have to add that (though it may seem obvious) when I changed from globals to types a lot of my programming problems went away. It's just good housekeeping, and in effect Blitz is acting as a spellchecker. So instead of Global CamX,CamY,CamZ Use TYPE Cam FIELD x,y,z END TYPE Then you have variables Cam\x, Cam\y, Cam\z. |
| ||
Just make sure and make your type identifier global, or else you might lose it :o) |
| ||
Normally Globals are faster than more structured programming, such as when calling a function passing a variable adds a copy of a memory address whereas a global uses the existing variable. But global's are harder to work with from a software design POV. eg. If you pass a parameter to a function and change it, you're changing a local value and not affecting other functions, but if you use a global you're changing the global value which can affect other functions that use that same global. Plus without explicit declarations in Blitz if you say mispell a variable it'll not cause a compile error but you're program will be bust. Using types, the object must exist first, and using local variables I find I'm less likely to forget or confuse variable names with global names. |
| ||
I'm with John. I put all of my variables inside of type instances - eliminating the debugging sessions associated with typos in variable names FAR outweighs any slight speed penalty I may incur. |
| ||
thanks fellas for all the input... --Mike |