• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Hashtable & variable array cost

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
i think on replace every array on my map with hashtables but i got a question, could make problem if i use alot hashtable (like 40)?

i used array like this var[player number*50+nr], this way i was able to save more data/player but could be better to create 1 hashtable for each player...

like: player_stat_hashtable[0-12] = create hashtable()
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
If you're creating a Hashtable, I would use one and only Hashtable, because their indexes are infinite, and you can use Values from 0 to 10.000 for player 1, 10.001 to 20.000 for player 2, and so on. it also works for any kind of object in the game. One Hashtable is enough, as long as you know how to handle it to make all the data fit correctly, and avoid the Hashleaks.

The downside of hashtables is that they're 3 times slower than variables when saving, and 2 times slower than variables when loading, because requires more arguments (4 to save, 3 to load); arrays just need 1.

As far as I know, hashtables stores the data as dinamically creating a variable for that slot; meaning you don't need pre-made Global Variables to store values for abilities or stuff you'll probably never use, but just create and use those you want and need when you want and need, and clear them later; avoiding memory waste.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
If you're creating a Hashtable, I would use one and only Hashtable, because their indexes are infinite, and you can use Values from 0 to 10.000 for player 1, 10.001 to 20.000 for player 2, and so on. it also works for any kind of object in the game. One Hashtable is enough, as long as you know how to handle it to make all the data fit correctly, and avoid the Hashleaks.

The downside of hashtables is that they're 3 times slower than variables when saving, and 2 times slower than variables when loading, because requires more arguments (4 to save, 3 to load); arrays just need 1.

As far as I know, hashtables stores the data as dinamically creating a variable for that slot; meaning you don't need pre-made Global Variables to store values for abilities or stuff you'll probably never use, but just create and use those you want and need when you want and need, and clear them later; avoiding memory waste.

i cant use 1 hashtable i have too many data, example i have 300+ item and i attach max 30-35 data for each item, then shop table with all existing item + description etc all of them permanent saved thing.

also if i do calculation in variable array index then overall the speed difference not closer between hashtable and v. arrays? coz id at hashtable dont ened math functions but array index yes...

i just curiosif i store same amount of data, in hash or in variable arrays, what better? (we talk about not too often used thing, like shoping/equiping item etc)

only place where i used hashtable and its often called thing is the Set Damage trigger from DDS, where i save the players damage on same boss
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You can use a single Hashtable; there's no limit for the amount of data you can store in a Hashtable, since Child and Parent Keys are infinite.

Storing and retrieving data on Hastable is slower in any case; unless you do a really bad math crap with the Array index math to find the right value.

Maths are faster than giving arguments to functions; besides, if you use some Indexing System for items/units you just need the Custom Value as replacement for HandleId, wich would be used with the Hash, along with the child key and the Hash itself.

If you find a suitable way to do it with an array, I woud suggest you to do it with the array.

300 items and 30-35 data in a Hashtable would be about 9.000 times this:
JASS:
call SaveInteger(Hashtable, ParentKey, ChildKey, Value)
Compared to Array wich would be
JASS:
local integer i = 0

set Items[i] = 'xxya'
set Data1[i] = value
set Data2[i] = value
set Data3[i] = value

set i = i+1
set Items[i] = 'asfd'
set Data1[i] = value
set Data2[i] = value
set Data3[i] = value
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
i know how to use the arrays, so not that the problem, also i know with hashtable is more line the permanent thing but since mostly is insertable to a loop so i dont care too much about it, anyway the saveing the alot data to hash is at map init so that np, reason why i opened the thread was the memory usage...

coz i hope dont have problem if i save alot thing to hash, dont make crash or lagg if too much thing was saved to hashtables
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Nah, there's no limit for hashs :) Certainly saving a lot of things into the has lags but just once, and other lag may result on loading too many stuff from the hash constantly.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Yep.

You would have to store an absurd amount of data in the Hashtable to make it lag.

Similar to having a periodic loop every 0.03 seconds creating a leak for 10 minutes, wich would result on 20000 leaks. If you store 20.000 stuff on the Hashtable you'll sense some "slowlyness" on the game, tough it depends on the ram and processors of each player.
 
Status
Not open for further replies.
Top