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

Is clear child necessary when overwriting in hashtable

Status
Not open for further replies.
Allow me to elaborate.

I am experimenting with using a hashtable to store what items is lootable/loaded into my custom inventory, when a corpse unit is being looted.

At a point in this process I need to overwrite a key in the hashtable.
  • Hashtable - Save Handle Of(Item carried by COM_DyingUnit in slot 1) as 1 of LOOT_UnitID in LOOT_Hashtable
The question is.
Do I need to clear the child of the LOOT_UnitID before storing a new item in the key or can I just overwrite it without any leaks?

If it is unclear what I mean please say so.
 
Example: if you do CreateTrigger() and then store that handle within hashtable, now lets assume that it is your only reference to retrieve that trigger handle, then overwriting that item within hashtable by another trigger handle reference will create a leak - you won't be able to free memory occupied by that trigger anymore (granted that you don't need that trigger to exist).

However, if you play with lets say integers, strings or reals you don't need to care. Also with handles, if you are able to retrieve stored handles in some other way.

There are plenty available hashtable tutorials which should help you with hashtables. You might also want to see Bribe's Table for perfect hashtable handling.

Clear function clears single item from hashtable, nothing more.
 
Example: if you do CreateTrigger() and then store that handle within hashtable, now lets assume that it is your only reference to retrieve that trigger handle, then overwriting that item within hashtable by another trigger handle reference will create a leak - you won't be able to free memory occupied by that trigger anymore (granted that you don't need that trigger to exist).

However, if you play with lets say integers, strings or reals you don't need to care. Also with handles, if you are able to retrieve stored handles in some other way.

There are plenty available hashtable tutorials which should help you with hashtables. You might also want to see Bribe's Table for perfect hashtable handling.

Clear function clears single item from hashtable, nothing more.

Informative. So if I get this right, only the usual stuff which needs to be remove in GUI needs to be extracted from the hashtable and the remove manually (points, regions, groups etc.). Right?
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Actually no. Flashing hashtables has nothing to do with reference data types and non-reference data types.
Hashtables get slower the more stuff you save in them, so you might wanna remove unused data. If you override the same "slot" with new data there is no need to flush first. This has nothing to do with objects that are or arent destroyed.
 
Actually no. Flashing hashtables has nothing to do with reference data types and non-reference data types.
Hashtables get slower the more stuff you save in them, so you might wanna remove unused data. If you override the same "slot" with new data there is no need to flush first. This has nothing to do with objects that are or arent destroyed.

Ah I see, But I assume if a point is saved in a hashtable and that is the only reference to said point I need to extract it and remove it before overwriting?

Also.
This corpse unit I was referring to earlier. It will get removed after a certain time period has passed. So again I assume it will be a good point to clear the child of the corpse unit at that time.
 
muzzel - it has, as explained in my example. If your code is clean and you know what to do, you don't really need to care. However, if you use hashtable for your struct members which posses fields such as trigger, unit etc. (lets say you store them inside hash) you better be removing/destroying those before flushing the hash.
If you don't, then when you want to destroy an instance of such struct you will lack possibility of retrieval of those handles.

Thats why it is important to note that. Although as stated, if you remove/destroy handles somewhere else in the code, you are free to flush whatever you want.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Ah I see, But I assume if a point is saved in a hashtable and that is the only reference to said point I need to extract it and remove it before overwriting?

Well yes, you should destroy stuff before you lose the last reference unless you want those objects to stay and do not need to address it anymore.

Clearing hashtables is not only for performance but you may check if an entry is unoccupied, if it's null, to use that as a special value.

Flushing a child hashtable is a lot faster than flushing multiple single entries.
 
Status
Not open for further replies.
Top