Snippet Recycle

Azlier

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

Troll-Brain

You can change this now in User CP.
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.
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.
 

Troll-Brain

You can change this now in User CP.
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™
>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.
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™
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.
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.
 
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
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?
 
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
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.
  • Ghan Ghan:
    The old shoutbox wasn't supported anymore. We updated xenForo, so it had to be replaced.
  • jonas jonas:
    let's see if everyone finds it... the nice thing about the shoutbox was I could check on it even while logged out, but the existence of this one is hidden when you're not logged in
  • Ghan Ghan:
    We can fix that.
  • Ghan Ghan:
    Chat should show on the sidebar when not logged in now.
  • Ghan Ghan:
    (You'll still need to log in to post messages)
  • Ghan Ghan:
    Test!
  • tom_mai78101 tom_mai78101:
    I must be in a test server.
  • tom_mai78101 tom_mai78101:
    Nice, Twitter tweets embedding now works
  • Wizard Wizard:
    Yup.
  • Ghan Ghan:
    Excellent.
  • Ghan Ghan:
    @tom_mai78101 Hello there.
  • Ghan Ghan:
    Tagging works in the chat too.
  • tom_mai78101 tom_mai78101:
    @Ghan Missed it.
  • Wizard Wizard:
    Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
  • Ghan Ghan:
    The venerable World Editor Tutorials site has been converted to HTTPS at last.
  • jonas jonas:
    cool
  • jonas jonas:
    and I can even edit my messages, nice
  • seph ir oth seph ir oth:
    GENERAL CHIT CHAT, YOU ARE A BOLD ONE
  • Ghan Ghan:
    Hello there
  • The Helper The Helper:
    this new chatbox is great and the forum software update is great too
    +1
  • The Helper The Helper:
    upgrade has fixed forum registration spam problem
  • tom_mai78101 tom_mai78101:
    Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
  • Wizard Wizard:
    Going to deploy a fix soon, just had to take some time for myself this weekend.
  • Varine Varine:
    Unbelievable. Time for yourself? How dare you!

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top