• 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.

Dynamically allocated array variables..

Status
Not open for further replies.
Level 26
Joined
Aug 18, 2009
Messages
4,097
Sure there are.

JASS:
native  InitHashtable    takes nothing returns hashtable

native  SaveInteger						takes hashtable table, integer parentKey, integer childKey, integer value returns nothing
native  SaveReal						takes hashtable table, integer parentKey, integer childKey, real value returns nothing
native  SaveBoolean						takes hashtable table, integer parentKey, integer childKey, boolean value returns nothing
native  SaveStr							takes hashtable table, integer parentKey, integer childKey, string value returns boolean
native  SavePlayerHandle				takes hashtable table, integer parentKey, integer childKey, player whichPlayer returns boolean
native  SaveWidgetHandle				takes hashtable table, integer parentKey, integer childKey, widget whichWidget returns boolean
native  SaveDestructableHandle			takes hashtable table, integer parentKey, integer childKey, destructable whichDestructable returns boolean
native  SaveItemHandle					takes hashtable table, integer parentKey, integer childKey, item whichItem returns boolean
native  SaveUnitHandle					takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean
native  SaveAbilityHandle				takes hashtable table, integer parentKey, integer childKey, ability whichAbility returns boolean
native  SaveTimerHandle					takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean
native  SaveTriggerHandle				takes hashtable table, integer parentKey, integer childKey, trigger whichTrigger returns boolean
native  SaveTriggerConditionHandle		takes hashtable table, integer parentKey, integer childKey, triggercondition whichTriggercondition returns boolean
native  SaveTriggerActionHandle			takes hashtable table, integer parentKey, integer childKey, triggeraction whichTriggeraction returns boolean
native  SaveTriggerEventHandle			takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean
native  SaveForceHandle					takes hashtable table, integer parentKey, integer childKey, force whichForce returns boolean
native  SaveGroupHandle					takes hashtable table, integer parentKey, integer childKey, group whichGroup returns boolean
native  SaveLocationHandle				takes hashtable table, integer parentKey, integer childKey, location whichLocation returns boolean
native  SaveRectHandle					takes hashtable table, integer parentKey, integer childKey, rect whichRect returns boolean
native  SaveBooleanExprHandle			takes hashtable table, integer parentKey, integer childKey, boolexpr whichBoolexpr returns boolean
native  SaveSoundHandle					takes hashtable table, integer parentKey, integer childKey, sound whichSound returns boolean
native  SaveEffectHandle				takes hashtable table, integer parentKey, integer childKey, effect whichEffect returns boolean
native  SaveUnitPoolHandle				takes hashtable table, integer parentKey, integer childKey, unitpool whichUnitpool returns boolean
native  SaveItemPoolHandle				takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean
native  SaveQuestHandle					takes hashtable table, integer parentKey, integer childKey, quest whichQuest returns boolean
native  SaveQuestItemHandle				takes hashtable table, integer parentKey, integer childKey, questitem whichQuestitem returns boolean
native  SaveDefeatConditionHandle		takes hashtable table, integer parentKey, integer childKey, defeatcondition whichDefeatcondition returns boolean
native  SaveTimerDialogHandle			takes hashtable table, integer parentKey, integer childKey, timerdialog whichTimerdialog returns boolean
native  SaveLeaderboardHandle			takes hashtable table, integer parentKey, integer childKey, leaderboard whichLeaderboard returns boolean
native  SaveMultiboardHandle			takes hashtable table, integer parentKey, integer childKey, multiboard whichMultiboard returns boolean
native  SaveMultiboardItemHandle		takes hashtable table, integer parentKey, integer childKey, multiboarditem whichMultiboarditem returns boolean
native  SaveTrackableHandle				takes hashtable table, integer parentKey, integer childKey, trackable whichTrackable returns boolean
native  SaveDialogHandle				takes hashtable table, integer parentKey, integer childKey, dialog whichDialog returns boolean
native  SaveButtonHandle				takes hashtable table, integer parentKey, integer childKey, button whichButton returns boolean
native  SaveTextTagHandle				takes hashtable table, integer parentKey, integer childKey, texttag whichTexttag returns boolean
native  SaveLightningHandle				takes hashtable table, integer parentKey, integer childKey, lightning whichLightning returns boolean
native  SaveImageHandle					takes hashtable table, integer parentKey, integer childKey, image whichImage returns boolean
native  SaveUbersplatHandle				takes hashtable table, integer parentKey, integer childKey, ubersplat whichUbersplat returns boolean
native  SaveRegionHandle				takes hashtable table, integer parentKey, integer childKey, region whichRegion returns boolean
native  SaveFogStateHandle				takes hashtable table, integer parentKey, integer childKey, fogstate whichFogState returns boolean
native  SaveFogModifierHandle			takes hashtable table, integer parentKey, integer childKey, fogmodifier whichFogModifier returns boolean
native  SaveAgentHandle					takes hashtable table, integer parentKey, integer childKey, agent whichAgent returns boolean
native  SaveHashtableHandle				takes hashtable table, integer parentKey, integer childKey, hashtable whichHashtable returns boolean


native  LoadInteger					takes hashtable table, integer parentKey, integer childKey returns integer
native  LoadReal					takes hashtable table, integer parentKey, integer childKey returns real
native  LoadBoolean				    takes hashtable table, integer parentKey, integer childKey returns boolean
native  LoadStr 					takes hashtable table, integer parentKey, integer childKey returns string
native  LoadPlayerHandle			takes hashtable table, integer parentKey, integer childKey returns player
native  LoadWidgetHandle			takes hashtable table, integer parentKey, integer childKey returns widget
native  LoadDestructableHandle		takes hashtable table, integer parentKey, integer childKey returns destructable
native  LoadItemHandle				takes hashtable table, integer parentKey, integer childKey returns item
native  LoadUnitHandle				takes hashtable table, integer parentKey, integer childKey returns unit
native  LoadAbilityHandle			takes hashtable table, integer parentKey, integer childKey returns ability
native  LoadTimerHandle				takes hashtable table, integer parentKey, integer childKey returns timer
native  LoadTriggerHandle			takes hashtable table, integer parentKey, integer childKey returns trigger
native  LoadTriggerConditionHandle	takes hashtable table, integer parentKey, integer childKey returns triggercondition
native  LoadTriggerActionHandle		takes hashtable table, integer parentKey, integer childKey returns triggeraction
native  LoadTriggerEventHandle		takes hashtable table, integer parentKey, integer childKey returns event
native  LoadForceHandle				takes hashtable table, integer parentKey, integer childKey returns force
native  LoadGroupHandle				takes hashtable table, integer parentKey, integer childKey returns group
native  LoadLocationHandle			takes hashtable table, integer parentKey, integer childKey returns location
native  LoadRectHandle				takes hashtable table, integer parentKey, integer childKey returns rect
native  LoadBooleanExprHandle		takes hashtable table, integer parentKey, integer childKey returns boolexpr
native  LoadSoundHandle				takes hashtable table, integer parentKey, integer childKey returns sound
native  LoadEffectHandle			takes hashtable table, integer parentKey, integer childKey returns effect
native  LoadUnitPoolHandle			takes hashtable table, integer parentKey, integer childKey returns unitpool
native  LoadItemPoolHandle			takes hashtable table, integer parentKey, integer childKey returns itempool
native  LoadQuestHandle				takes hashtable table, integer parentKey, integer childKey returns quest
native  LoadQuestItemHandle			takes hashtable table, integer parentKey, integer childKey returns questitem
native  LoadDefeatConditionHandle	takes hashtable table, integer parentKey, integer childKey returns defeatcondition
native  LoadTimerDialogHandle		takes hashtable table, integer parentKey, integer childKey returns timerdialog
native  LoadLeaderboardHandle		takes hashtable table, integer parentKey, integer childKey returns leaderboard
native  LoadMultiboardHandle		takes hashtable table, integer parentKey, integer childKey returns multiboard
native  LoadMultiboardItemHandle	takes hashtable table, integer parentKey, integer childKey returns multiboarditem
native  LoadTrackableHandle			takes hashtable table, integer parentKey, integer childKey returns trackable
native  LoadDialogHandle			takes hashtable table, integer parentKey, integer childKey returns dialog
native  LoadButtonHandle			takes hashtable table, integer parentKey, integer childKey returns button
native  LoadTextTagHandle			takes hashtable table, integer parentKey, integer childKey returns texttag
native  LoadLightningHandle			takes hashtable table, integer parentKey, integer childKey returns lightning
native  LoadImageHandle				takes hashtable table, integer parentKey, integer childKey returns image
native  LoadUbersplatHandle			takes hashtable table, integer parentKey, integer childKey returns ubersplat
native  LoadRegionHandle			takes hashtable table, integer parentKey, integer childKey returns region
native  LoadFogStateHandle			takes hashtable table, integer parentKey, integer childKey returns fogstate
native  LoadFogModifierHandle		takes hashtable table, integer parentKey, integer childKey returns fogmodifier
native  LoadHashtableHandle			takes hashtable table, integer parentKey, integer childKey returns hashtable

native  HaveSavedInteger					takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedReal						takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedBoolean					takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedString					    takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedHandle     				takes hashtable table, integer parentKey, integer childKey returns boolean

native  RemoveSavedInteger					takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedReal						takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedBoolean					takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedString					takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedHandle					takes hashtable table, integer parentKey, integer childKey returns nothing

native  FlushParentHashtable						takes hashtable table returns nothing
native  FlushChildHashtable					takes hashtable table, integer parentKey returns nothing
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
for storing you can do Hashtable - Save unit(for instance) as childkey(any number) of parentkey(any number) on whichhashtable(if you have only 1 you're fine with last created hashtable)
yes, if you want load unit for instance
you want to kill unit you go to function unit - kill unit and change the triggering unit into hashtable - load handle and you add which hashtable, childkey, parentkey.

Remeber that you can't save 2 handles into the same parent key - child key and if you want to retreive the unit you need to add the correct childkey and parrentkey otherwise it will return null instead of handle.
You can save(I think someone here on forum proved it) different type of "native" types(for instance you can have integer and real in the same parent key - child key )
edit: hope you understand it
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Parent key is something we use this to create;
  • Actions
    • Hashtable - Create a hashtable
    • Set Hashtable = (Last created hashtable)
Where Child key is used to save data to something, well, this will save a value of '5' to a unit that cast the spell;
  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Animate Dead
    • Actions
      • Set Value = 5
      • Set Caster = (Triggering unit)
      • Custom script: set udg_ChildKey = GetHandleId(udg_Caster)
      • Hashtable - Save Value as 0 of ChildKey in Hashtable
ChildKey is Integer variable.
Okay, that will save a value of '5' to the Caster (Triggering unit).

To load it, simply;
  • Actions
    • Set Caster = (AnyUnitEventYouWant)
    • Custom script: set udg_ChildKey = GetHandleId(udg_Caster)
    • Set Value = (Load 0 of ChildKey from Hashtable)
    • Game - Display to (All players) the text: (String(Value))
The game will show value of 5, meaning that you have successfully save and load the value from a correct unit.

Each time you have no use of the data, simply;
  • Actions
    • Hashtable - Clear all child hashtables of child ChildKey in Hashtable
To clean the data that will save the system's performance of the game.
Do not clear Parent Key if you're still gonna need them.
Because if clear Parent Key, it's the same as you destroy a Headquarters.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Yeah, Integer = GetHandleId(Unit)
  • Actions
    • Set Value = 5
    • Set Caster = (Triggering unit)
    • Custom script: set udg_ChildKey = GetHandleId(udg_Caster)
    • Hashtable - Save Value as 0 of ChildKey in Hashtable
You see, first we set what value we want to store and which unit is to take that value.
Next, I used Custom script to allow the data to be saved to that unit.
After that I save '5' as Value, 0 (this is nothing, actually it's some sort of memory reference, for now just use 0 1 2 for different types of variable), ChildKey, Hashtable.

Basically, what we do is Integer = GetHandleId(Unit), this will set that the Integer (ChildKey) will save a data to the Unit (Caster).
 
read the tutorial dude http://www.hiveworkshop.com/forums/...9/complete-beginners-guide-hashtables-197381/

and you can save/load up to 1 BILLION in GUI, in jass maybe more...
  • Untitled Trigger 007
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Hashtable - Save 123 as 1000000000 of 1000000000 in HASH
      • Game - Display to (All players) the text: (String((Load 1000000000 of 1000000000 from HASH)))
this will display the 123

EDIT:
if you want storage then hashtables is very useful but it's around 70-90% slower than indexing systems and UnitIndexers...
 
Level 6
Joined
Jul 25, 2010
Messages
136
read the tutorial dude http://www.hiveworkshop.com/forums/...9/complete-beginners-guide-hashtables-197381/

and you can save/load up to 1 BILLION in GUI, in jass maybe more...
  • Untitled Trigger 007
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Hashtable - Save 123 as 1000000000 of 1000000000 in HASH
      • Game - Display to (All players) the text: (String((Load 1000000000 of 1000000000 from HASH)))
this will display the 123

EDIT:
if you want storage then hashtables is very useful but it's around 70-90% slower than indexing systems and UnitIndexers...

based here.. I can use any integer and i can attach it to any unit?
anyways thanks everyone i appreciate your help.. i get what is the use of hashtable.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You do not need to attach it to a unit/object but it is common practice if the saved value shall express an attribute of that object. As shown, it is also rather assigned to the provided id, not natively directly to the object. So if something happens to the object, you need to alter the hashtable data yourself. A unit's disappearance won't clear hashtable fields of its id for example because the hashtable only knows the keys as integer numbers. And object ids might be recycled after the former owner has been released.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Yes but as shown, you can emulate it in a hashtable for example because they are large enough to split them up. You only have to have an algorithm that fetches you new keys everytime. Otherwise, wc3 allocates memory for new objects such like units. You could theoretically create a unit and set some properties like custom value. Or create a group and add different units to it. That would be a form of dynanism but would be inconvenient and non-performant as hell.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Objects can leak, especially non-interactive stuff like locations because you won't pick them up otherwise. Also local variables get allocated. I do not want to say that those would leak on their own as they are cleaned up at the end of the function but there is this known bug. References to a lot of objects like variables are counted and those objects, even when removed via functions, only get completely freed after they are not referenced anymore. Local variables in wc3 have the issue that they do not automatically dissolve this reference to the object they finally pointed to when being terminated. So when you do not null local object variables, the objects won't be wholly released and therefore become a leak.

Example:

JASS:
function bla takes nothing returns nothing
    local location l = Location(0, 0)  //creates a new location object and stores it in the local variable l

    call RemoveLocation(l)  //the location object that is stored in l gets destroyed but some memory is still occupied because l points to it

    set l = null  //l gets detached from the memory it formerly pointed to, this memory is no longer referenced and the object destroyed, so it can finally be released, if that line was missing, the reference would persist and therefore the memory demand
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
The problem with local variables is they do not automatically decrement the handle reference counter for objects at the end of the function. This leaks a count against the handle preventing it from ever being recycled practically. You can force a decrement by setting the handle to null. Not all handles can be recycled as some are staticly allocated (like players).
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
@Dr Super Good: I meant those are not reference-counted, so their variables do not need to be nulled.

Well, it is not like you could avoid every leak in wc3 because some are infested in native functions, the engine, string generation, records for the replay file, non-existing destroy functions etc etc.

Of course, the worst would be that you lose full objects.
 
Status
Not open for further replies.
Top