Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 When should I use global, instance, local, and constants in event systems?
#15
Ah yes, I see Wolfie. That is indeed misleading.
What they failed to mention is how much memory is actually used. Totally insignificant except in the most extreme cases which certainly never have happened in RMXP or RMVX unless caused by a bug. (Not including specifically designed tests)
They may have been thinking about how the referenced object, which can be of a significant size, may be present in the memory all the time since the user just used a global variable rather than a local variable.
At this point I think I should remind you that when the scope of a local variable ends the local variable is freed, but the object it references is NOT freed. For freeing objects you have the Garbage Collector (GC) which frees objects you have no reference to (under transitive closure). If the local variable was the only reference to the object then the object will freed whenever the GC gets to it. You can't really know when the GC runs unless you force start it with GC.start. (It is generally preferable to let the GC manage itself)
What now if you have a global variable and want the object it points to freed? Just do something like $global_variable = nil. Actually it can be anything other than the current object.
If there are no more references to the object then the GC will take of it.

The rest of what Tricky wrote is pretty much true. (Note: I think than on a 1-to-1 ratio local variables might use more memory than global variables since they are in a dynamic scope as opposed to a static scope.)

Global variables are NOT resource hogs unless you consider humans as a resource. Then it might be so.
For the CPU global variables are insignificant.

*hugs*
- Zeriab

Edit:
@Charlie: The idea is that global variables don't disappear after introduced so they keep using memory where as local variables are disposed and therefore the number of variables would generally be lower.
For the scope of an RPG Maker XP or VX game I really believe the difference to be insignificant. Maybe it's only for 99 % though.
Reply }


Messages In This Thread
When should I use global, instance, local, and constants in event systems? - by Zeriab - 12-28-2008, 08:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Popular Battle Systems kyonides 6 6,453 02-24-2022, 10:40 PM
Last Post: kyonides
Brick Common Event Library (Development + Brainstorm thread) PK8 3 9,083 02-11-2016, 09:25 PM
Last Post: JayRay
   What do you dislike in ATB Systems? DoubleX 18 22,319 06-13-2015, 05:03 AM
Last Post: DoubleX
   What Makes an Event System DerVVulfman 8 13,022 01-19-2010, 09:07 PM
Last Post: Bolt
   What is "event scripting?" PK8 11 16,390 12-19-2008, 11:20 PM
Last Post: PK8



Users browsing this thread: