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

integers efficiency over reals?

Status
Not open for further replies.
Level 4
Joined
Feb 22, 2012
Messages
74
I am wondering if using integers over reals is significantly more efficient as far as hashtables and global variables.

I could change many of my over-time spells. Because they are all based on either a 0.04 second (for missiles), or a 0.20 second (for damage over time) timer, I could save their "durations" as integers (number of ticks) instead of reals.

I have uploaded the map I am working on so you get a sense of how many globals there are for just one hero. As you can see, the Living Bomb spell is not even started and the secondary effect of the Wither Spell is not in yet. Would changing some of those variables to integers save some memory?

Also a newb question about leaks: if you destroy / remove a variable do you still have to set = null before you re-use it?
 

Attachments

  • testmap.w3x
    76.5 KB · Views: 82
Also a newb question about leaks: if you destroy / remove a variable do you still have to set = null before you re-use it?
For your newb question, the answer is no.
But you don't have to set it to null every time ^^ It don't create bugs afaik. It's always better to do it, but not an obligation.


In my spells, i use Reals, since it's easier to understand (The spell lasts 5seconds or The spells lasts 120 Ticks) It's also better to use integer if for example : every 3ticks, a special effect is created ^^ (easier to configure it without problem)
But afaik, a real and an integer take the same memory.

Also, 0.04 seconds should be 0.03 seconds (always better except if the spell need hard perfomances).
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,243
I am wondering if using integers over reals is significantly more efficient as far as hashtables and global variables.

There was some discussion here: http://www.hiveworkshop.com/forums/triggers-scripts-269/benchmarks-truth-out-there-201810/

The bottom line is that there is not much difference, don't worry about that.

Also a newb question about leaks: if you destroy / remove a variable do you still have to set = null before you re-use it?

You can't destroy/remove variables in JASS. Global variables do not need to be nulled.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Vladadamm said:
But afaik, a real and an integer take the same memory since both are Handles.

No they are not handles, but i don't remember if they take the same memory or not, it's probably the same, else the rerturn bug wouldn't work that much in the previous patches, anyway with wc3, the memory is not a real problem, as long you care about leaks, especially with the actual computers nowadays.

It don't create bugs afaik. It's always better to do it, but not an obligation.

At least it will leak handles ids if it was a local variable, if it was a global variable, as long the variable will be re-used that won't leak an handle id.
People say that it will make the jass vm (remember that GUI is just an ugly jass) more and more slower with more and more handle id leaks, i have never tested myself this claim, but it makes sense.

Also, 0.04 seconds should be 0.03 seconds (always better except if the spell need hard perfomances).

Depends what you need to do, even depends humans, some people will notice a difference with 2 different fps, some other won't.

Maker said:
Global variables do not need to be nulled.

For the sake of accuracy, unless this bug was fixed (sorry i'm unable to find the leak on thehelper.net yet, cause there is a bug in this forum, i will edit and give it later), in order to prevent any memory leak even for globals it would be better to null them also, but you can't always do it, and it's just a tiny memory leak, not an handle id one, so don't care about it is just fine.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
In order for a handle index to be recycled, all references to it have to be nulled. When you change the value of a handle variable it decrements the reference counter for the current value and increments the reference counter of the new value.

With globals this means that a handle index can only be blocked until a new value is assigned to the variable. You can still leak handle indices when code to assign new values is un-reachable. The number of handle indices that can leak is limited to at most 1 per global storage location so the leaks can easily be ignored without any real concern. When using handle arrays leaks can become more of a concern as each variable represents up to 8192 storage locations (which can translate to a considerable number of leaked handle indices) so care has to be taken that all indices that will not be readily overwritten get nulled.

Function argument declared local variables never have to be nulled. They automatically decrement the reference counter of the contained handle at function return.

The major problem is locally declared local handle variables as those do not automatically decrement the reference counter on function return. This means that if you used a local to reference a location and forget to null it before the function returns the handle index used by the location will permanently leak (well as good). Unlike globals which can leak at most a static number of handle indices, locally declared locals can leak a handle index per function call. This means that periodic functions will cause more handle leaks as the game progresses.
 
No they are not handles, but i don't remember if they take the same memory or not, it's probably the same, else the rerturn bug wouldn't work that much in the previous patches, anyway with wc3, the memory is not a real problem, as long you care about leaks, especially with the actual computers nowadays.
Yes, you're right, just a little fail from myself. I go edit that...
 
Status
Not open for further replies.
Top