• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] I have two questions.....

Status
Not open for further replies.
Level 9
Joined
Oct 11, 2009
Messages
477
Q1:Do Hashtable Handles leak? If yes, how to clean them?

Q2: How to save and load independent data(real, integer, unit, destructible, etc.) of units, destructibles, etc. without using a Hashtable? I'm wondering if that can be done only in JASS but is there a way in GUI?
 
A1:Yes, when you init an hashtable, you actually create an handle and if you don't want to use it anymore, you should destroy it. But in fact, you are coding very bad if you use a lot of hashtables in jass and leak is not you first priority. One hashtable is largely enough in most case.

A2:You can use a vJass unit indexer or a game cache like this :
  • Game Cache - Store handle as MyHandle of (String((Key (unit)))) in (Last created game cache)
It was used a lot before hashtables appeared but since it's less efficient and slower, it's not used anymore.
If you don't want to use hashtables or game caches, you would have to simulate a vJass unit indexer in GUI which can certainly be done but would be ugly.
 
Level 9
Joined
Oct 11, 2009
Messages
477
E1: Then that means....
  • Hashtable - Save handle of (Picked unit) as Key(Picked unit) of Key(Picked unit) in (Last created hashtable)
This part Key(Picked unit) does not leak?
 
No, it does not leak at all. Picked Unit does not leak, and Key(Picked Unit) gets the unit's handle id (integer). No leaks.

If you save 2 ^ 32 (an extremely high number) of things in a hashtable, that's when you hit the hashtable's storage limit. The game consumes about 2 GB of RAM at that point XD

Good thing is it would take a LOT of effort even get close to that limit.
 
Level 14
Joined
Nov 18, 2007
Messages
816
The handle is an integer and integers do not leak am I right?
Partly: Integers dont leak, yes.
But handles are not integers, handles are a different primitive type. Every handle can be "casted" into an integer, though (which is what GetHandleId() does). Every handle has an ID, which is unique for all subtypes of handle (there are no two units with the same ID that are not the same unit), some even share a stack of IDs (units, groups, timers, and a few more. This means that if a unit has a certain ID, there can be no group with the same ID).

Anyway, if you ever have to destroy a hashtable handle, youre doing something VERY wrong. So dont worry about hashtables leaking.

There are arrays...
 
Status
Not open for further replies.
Top