• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Hashtables or globals ?

Status
Not open for further replies.
Level 2
Joined
Dec 14, 2012
Messages
20
In my current my I store my unit's using globals.


Lets say I want to kill a unit after 5 sec when it attacked me ill then store then unit under a global unit. now would it be better to store it under a hashtable ? And can a map have to many globals?
 
Level 7
Joined
Apr 5, 2011
Messages
245
I am not using hashtables, considering that some spells are very difficult comparing to Dota. So, if question is about functionality, it can work perfectly without any bugs / lags even on my slow PC. Though for cases when spells are extremely spammable hashtable is probably faster, but even Dota WTF does not really need this.
Though I am not an expert in hashtables, I don't even know how to work with them, only what is it, so my point may be not enough expert :O
 
Level 2
Joined
Dec 14, 2012
Messages
20
I am not using hashtables, considering that some spells are very difficult comparing to Dota. So, if question is about functionality, it can work perfectly without any bugs / lags even on my slow PC. Though for cases when spells are extremely spammable hashtable is probably faster, but even Dota WTF does not really need this.
Though I am not an expert in hashtables, I don't even know how to work with them, only what is it, so my point may be not enough expert :O

I am just wondering if u will get lag? cuz my map is already just as big as dota. Hashtables seems to be easy to use but yea i agree with u why use it if globels are fine
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
There are legitimate reasons to use hashtables. Using them as an alternative to arrays isn't one of them. There are already more than 100 global variables declared ("last created unit", "last created group") by warcraft 3 itself before you even create a single "user defined" global. In other words: don't worry about having too many globals. Don't worry about lag either: an array is at least twice as fast as a hashtable, and hashtables only get slower as more variables are stored in it.
 
hashtables are slower than arrays to begin with and yes as eleandor has said they get slower with more info added to them.

u can use indexed arrays for spells. And if u need u can use arrays keyed with the units custom value to load certain data just like u would from a hashtable.

indexed arrays are slightly faster than arrays with unit indexer being used but not much faster.

look at my tutorial things a guier should know.
the chapter how to index has indexed array method being used there.
i believe i also have a chapter on hashtables with more information about them in there.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Globals are always faster than hashtables. Hashtables are always more flexible than globals.

Use hashtables when the situation demands a process that is difficult to map to an index of an array (like mapping object types to data). Use arrays for bulk storage and when mapping to indicies is very easy (like instances of a periodic ability).

Hashtables do not resize their bucket array (at least beyond a certain size). This means using them for bulk data storage (or leaking data in them) degrades their performance considerably. If you want to store several pieces of data (eg an ability instance) it is better to use parallel global arrays and then save the index of the instances using the hashtable.
 
Status
Not open for further replies.
Top