Calling Data Efficiently

A slightly random question from me, but I was wondering which of the following would be quicker/ better/ more efficient..

 

Option A :: Calling data directly from the module like so...

Code:
MainModule::Sub_Module::Data[@id]

 

Option B :: Creating a global variable at run time, as below..

Code:
$module_data = MainModule::Sub_Module::Data

And then calling the data like this...

Code:
$module_data[@id]

 

The reason I'm asking is because I feel that using a variable would dramatically neaten some of my code; however, alot of people have negative views on over-using global variables as they take space etc..

I also feel that it would be quicker to call the data directly from a variable rather than calling data thats being stored within a 'sub module'.

Anyway, anyone have any insight to this?
I generally stick all my things into $game_temp or $game_system(things that need to be save go in here). that way I can use a variable that exists anyway. You would probably want to give your variables a special prefix, though, to redice any conflict chance.
Yes, of course, if I was wanting to save the data and it was a small piece of random data, like a small array or a text extract then that would have been my first thoughts.

As the data in question is VERY large ie, a hash that contains numerous other smaller hashes, arrays, text and symbols. It is stored very similar to the way the database information is retained. I also do not want or need to save the data (the data can never change or be increased) or I would have just done something like this...

#===============================================================================module DataManager#===============================================================================  #---------------------------------------------------------------------------  # Alias List  #---------------------------------------------------------------------------  class << self    alias :cgo_alias :create_game_objects    alias :msc_alias :make_save_contents    alias :esc_alias :extract_save_contents  end  #---------------------------------------------------------------------------  # Create Game Objects (alias)  #---------------------------------------------------------------------------  def self.create_game_objects    cgo_alias    $module_data = Main_Module::Sub_Module:😀ata  end  #---------------------------------------------------------------------------  # make save contents (alias)  #---------------------------------------------------------------------------  def self.make_save_contents    contents = msc_alias    contents[:my_stuff] = $module_data    contents  end  #---------------------------------------------------------------------------  # extract save contents (alias)  #---------------------------------------------------------------------------  def self.extract_save_contents(contents)    esc_alias(contents)    $module_data = contents[:my_stuff]  endend # DataManager
I'm simply wondering which method would be quicker.

However, upon reflection, it could be wise (for further in my project development) to allow for the data to be modified after the initial creation... Hmmm...
for me in my practices as a programmer, I always keep away of making globals or registry because as your codes grows many of your codes are dependent on it and you wouldn't know what code is changing the values on the globals...

for example in the situation that module A is using global A then module B uses also global A and global A changes the value and module B will be uncontrollable in the situation that you will create a variable that will hold the previous value of the global A.

the next thing is if you use globals you keep on creating an overhead on the global scope. for example a part of the game the runs the map will always run down on the global variables for the global variable for sprites even the map script doesn't need it. the rule is the bigger the collection the larger the overhead. the slower it is the messier it is.

so in my conclusion the cleanest way for me in this kind of situation is to keep away from saving object on globals and keep these variables under their own scope. which means I really prefer the Option A.
Yea, I thought that would be the case :/

Was just trying to save some time with the coding 😛

Thanks for your input 🙂

Original thread: https://forums.rpgmakerweb.com/threads/calling-data-efficiently.22646/