Snippet Recycle

Azlier

Old World Ghost
Reaction score
461
The only real use for recycled triggers are for Events. And that's almost never needed.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Do you still have to null locals? I saw some people's code using this but they weren't nulling.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I don't see the usefulness of it in the current state, since with this library only, you can't attach an integer (struct) to a timer -> TimerUtils.
You also doesn't prevent double free, at least in debug mode, same for groups -> GroupUtils (but i don't like this last code to be honest).
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Sometimes i use groups for more than an instant, even if this case is minor i still prefer have a GroupRefresh function.
But as i said, i really don't like the way how GroupUtils was build, in fact i've edited it for myself.
The result, the speed is actually the same as this script in not debug mode, and in debug mode it prevents me for double free.
 

Jesus4Lyf

Good Idea™
Reaction score
397
The result, the speed is actually the same as this script in not debug mode, and in debug mode it prevents me for double free.
Cool! :D

This script could prevent double free, the cost is it cannot be used on 1.23 (rapidly fading usefulness). :p

Could ask Nestharus to add it.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Bwah honestly i don't care about that for this script, since i won't use it anyway, because of what i said.

Or maybe you have an other idea of recycling which is not a group, neither a timer ?

Btw i used a dummy unit for group utils, so it's still fully compatible with all versions of war3, but ofc it can't be used for this generic handle script.

EDIT : Heh i forgot the new static ifs, you could generate this kind of script.
If you don't know how, simply declare a boolean with the textmacro and use it in a static if to generate the right code.
But still ofc i guess we can't work like that with all handle types.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Btw i used a dummy unit for group utils, so it's still fully compatible with all versions of war3, but ofc it can't be used for this generic handle script.
Using something like that for double free protection seems counter-intuitive. Surely, the unit may have been removed from the group before being freed for a second time - such as if any enum was called for it...
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Using something like that for double free protection seems counter-intuitive. Surely, the unit may have been removed from the group before being freed for a second time - such as if any enum was called for it...

The unit is inside freed groups only and a debug message is displayed if you try to freed it again, but maybe i've missed something.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Yes, if the group is used at all with an Enum or FoG loop, your protection is shot. You seemingly would only save double free protection if it is immediately two calls. But that's not very useful... most likely the user (yourself? XD) would accidentally keep a reference to the group, and try using it for something, and then free it again...

Hm.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Yes, if the group is used at all with an Enum or FoG loop, your protection is shot. You seemingly would only save double free protection if it is immediately two calls. But that's not very useful... most likely the user (yourself? XD) would accidentally keep a reference to the group, and try using it for something, and then free it again...

Hm.

I don't use myself FoG loop, hence the reason.
Bwah i guess personal codes are perfect for personal purposes.

I just want to add that double free can happen more quickly than you think, even if you're the best coder ever.
 

Nestharus

o-o
Reaction score
84
On Data Attachment
Actually, I was thinking of doing an add-on to this (a module) that would do data attachment on timers and groups, but I stopped it. The reason is it'd only be a few lines.. it'd just get an offset... it'd be such a tiny little script, lol. From there you'd use the offset for the array index =).

This would actually be the code for it ^^

JASS:
library Memory initializer Initialization uses Recycle
{
    struct Memory {
        public static int offset
        
        public static timer privateTimer = CreateTimer()
        public static integer array data
        define <Memory.set>(handleId, value) = {
            Memory.data[handleId-Memory.offset] = value
        }
        
        define <Memory.get>(handleId) = {
            Memory.data[handleId-Memory.offset]
        }
        
        public hashtable memory = InitHashtable()
        define <Memory.set>(handleId, slot, value) = {
            SaveInteger(Memory.memory, handleId, slot, value)
        }
        
        define <Memory.get>(handleId, slot) = {
            LoadInteger(Memory.memory, handleId, slot)
        }
    }

    private void Initialization() {
        Memory.offset = GetHandleId(Memory.privateTimer)
        Timer.release(Memory.privateTimer)
        Memory.privateTimer = null
    }
}



And here is a demo
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"


scope Demo initializer Initialization {
    timer t
    int data
    
    void Test() {
        data = Memory.get(GetHandleId(GetExpiredTimer()))
        printf(I2S(data))
    }
    
    void Initialization() {
        t = Timer.get()
        Memory.set(GetHandleId(t), 5)
        TimerStart(t, 1, false, function Test)
    }
}



So do you guys really want me to submit this (when and if cJASS gets approved, lol)
 

Weep

Godspeed to the sound of the pounding
Reaction score
401
Yes, if the group is used at all with an Enum or FoG loop, your protection is shot. You seemingly would only save double free protection if it is immediately two calls. But that's not very useful... most likely the user (yourself? XD) would accidentally keep a reference to the group, and try using it for something, and then free it again...
Wait, what? You can double-free with groups? I haven't been able to find any mention of how that can happen. Could you explain?
 

Nestharus

o-o
Reaction score
84
He's talking about Troll-Brain's method of double free protection =P


But yes, you could in fact double free a group with Recycle too : )


Group.release(group1)
Group.release(group1)

and there is the double free : D
 

Weep

Godspeed to the sound of the pounding
Reaction score
401
Oh, so it's a system-index double-free, not a handle double-free as can happen with destroying timers or triggeractions?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top