HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Question About Global Variables and When to "Destroy" Them

03-21-2006, 10:09 AM#1
hourglasseye
Hi,

I have been wondering which would be better. Let us say that i have a global variable named udg_reusablePoint and at some point, I would assign a point to it (the center of a region for example, where creeps spawn). This point is to be used more than once and rather frequently (periodically, every 20 seconds). Assume that it will be used until the game ends.

Which would be better? To assign the center of the region to udg_reusablePoint at map initialization and keep it there (since it is always used)? Or to assign it and then destroy it everytime I use it?
03-21-2006, 10:26 AM#2
Jacek
Of course faster way is to assign and keep it.
03-21-2006, 02:59 PM#3
Anitarf
But then that point variable is not really "reusable" in a sense that you could use it for all temporary location objects.
03-21-2006, 10:57 PM#4
hourglasseye
Do you mean that I can assign a different value for that variable (so the previous value is no longer reusable)? Hmm, that wouldn't be a problem when I never modify it after its initiaaaaal... instanciation? Would it?

Oh, and when I assign a different value to it, does the older value gets overwritten? Or does is go floating about eating space? (._.)?
03-21-2006, 11:21 PM#5
Anitarf
Quote:
Originally Posted by hourglasseye
Do you mean that I can assign a different value for that variable (so the previous value is no longer reusable)? Hmm, that wouldn't be a problem when I never modify it after its initiaaaaal... instanciation? Would it?
No, not a problem, but it's more of a static variable then, you use it only for having a reference to that one location; there's nothing wrong with that, just the name of the variable feels odd in such a case, "reusablePoint" instead of something like "spawnPoint1" or whatever.
Quote:
Oh, and when I assign a different value to it, does the older value gets overwritten? Or does is go floating about eating space? (._.)?
In case of atomic variables (int, bool, real), it gets overwritten. In case of handle objects, the variable is just a pointer and the actual object remains in memory unless you destroy it.