wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-26-2009, 05:57 PM   #1
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default Should I null triggers?

Hi guys, I am teaching student of mine into the world of vJass and good coding practice (as Anitarf and Pyro thought me). So I told my student that in a regular case of a spell, we can make our triggers local like this
Collapse JASS:
private function Init takes nothign returns nothing
    local trigger Trg = CreateTrigger()
endfunction

And I also said him, that we don't need to make
Collapse JASS:
set Trg = null
(in that case) because Trg is not really an object, it is a pointer, so it's leak can be compared to an integer's leak. This way if we null the trigger we will be actually making our code slower because we waste time with useless stuff.
However I have other guy, showing up in the thread, and he says I have to null all triggers because they are handles.

We went though a discussion, and we didn't reach any solid conclusions ...
So, I am asking here, what should I do? Should I null or not null the triggers?
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 04-26-2009 at 05:58 PM.
Flame_Phoenix is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-26-2009, 06:07 PM   #2
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

handle equals pointer in our case...
the reason why we dont have to null triggers is, that they wont be destroyed ever ...
except when you have dynamic triggers, but we shouldnt use those anyway...
__________________
akolyt0r is offline   Reply With Quote
Old 04-26-2009, 06:10 PM   #3
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Quote:
So I told my student that in a regular case of a spell, we can make our triggers local like this
student? uh oh.

First of all, always null handle local variables when they reach the end of their 'scope', always. Plenty of times, it is not necessary to null a local. But turning the nulling into a mechanical process while trivializing it is better than having to give thought to such a lame thing... Just to save a couple of lines of codee...


However, if this is your typical spell trigger, it is true you don't have to null it.
Quote:
in that case) because Trg is not really an object, it is a pointer, so it's leak can be compared to an integer's leak.
Wrong. First of all, you are not worried about the pointer itself leaking, the reason you null locals is because of the handle's index.

The first thing to notice is that handle indexes are ref-counted , even if you call a Destructor (IE RemoveLocation) on a handle, its index will remain alive until all references against it are down. When you call a Destructor, a 4 bytes handle "ghost" will remain in its location.

What happens here, is that there is a blizzard bug, references for local variables don't go down automatically when a function's scope ends. So we set them to null so the reference counter goes down, and the index can be recycled (and we can get those 4 bytes back)

The bytes are not an issue unless you have this leak multiple times, however, the indexes are a problem.


Collapse JASS:
function err takes nothing returns nothing
 local location loc = Location(0, 4.5)
   call RemoveLocation(loc)
endfunction

This line of code leaks. We are removing the location object, however, the bug prevents wc3 to notice loc's index is no longer in use. And thus this index will leak.

Collapse JASS:
function err takes nothing returns nothing
 local location loc = Location(0, 4.5)
   call RemoveLocation(loc)
 set loc = null
endfunction
This does not leak anymore.

Anyway, if the handle held by the variable is not EVER destroyed, then you don't have to null it. That's the real reason that in the case you pointed, you don't need to null the variable.


Quote:
This way if we null the trigger we will be actually making our code slower because we waste time with useless stuff.

Aw, give me a break, no, this doesn't matter at all.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-26-2009, 06:47 PM   #4
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Ahhh... Thx for explaining this detail to me guys!

Quote:
Aw, give me a break, no, this doesn't matter at all.
Lol, quite funny, having in mind some people like Anitarf or HindyHat use that argument as a reason to "do not null local triggers".
Tell that to them, not to me xD
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 04-26-2009, 07:03 PM   #5
Strilanc
User
 
Strilanc's Avatar
 
Join Date: Jun 2007
Posts: 917

Submissions (4)

Strilanc has a spectacular aura about (131)

2008 Spell olympics - Fire - Gold

Default

Vex, I find it ironic that you ended your post about nulling permanent triggers with "this doesn't matter at all" (in another context).

I should try to write a tool to insert the local-nulling automatically someday. It would just be a matter of identifying functions, finding the exit points, and assigning the locals to temp globals if they're needed for the return statement.
__________________
Don't pay attention to this signature, it's self-contradictory.
Strilanc is offline   Reply With Quote
Old 04-26-2009, 09:42 PM   #6
TheKid
User
 
TheKid's Avatar
 
Join Date: Mar 2009
Posts: 195

TheKid will become famous soon enough (37)TheKid will become famous soon enough (37)

Default

So as soon as there are no more variables referencing a specific handle it will recycle the handle ID (given the actual handle has been destroyed/removed)?
TheKid is offline   Reply With Quote
Old 04-26-2009, 09:48 PM   #7
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,186

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by TheKid
So as soon as there are no more variables referencing a specific handle it will recycle the handle ID (given the actual handle has been destroyed/removed)?
It will recycle the id when it is needed: that is, when another handle needs to be created; but you are correct, in order for an id to be recycled, the handle stored there needs to be destroyed and it's reference counter needs to be at zero which means no variables are pointing to it (and no local variables have been pointing to it at the time their function returned).
__________________
Anitarf is offline   Reply With Quote
Old 04-27-2009, 08:14 AM   #8
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Now I am confused with a question .. as far as I understood, we only need to set something to null when we destroy it. If we never destroy it, we don't need to set it to null right?

So, imagine I have a map with a unit called Chuck Norris. Chuck Norris is all mighty, all powerful and is also indestructible. Imagine also that Chuck Norris can cast a spell called roundhouse kick. So imagine this function
Collapse JASS:
private function Actions takes nothing returns nothing
    local unit God = GetTriggerUnit()

    //effect of the spell and destruction of the Universe as we know it...

    //end of spell
    //having in mind Chuck Norris will NEVER die not be destroyed, should I null the unit variable?
endfunction


So basically, after the destruction of the universe, and having in mind Chuck Norris is a unit that will never die, should I null him?

PS: Any answer to this post is wrong, Chuck Norris level of awesomeness cannot be contained in any computer nor machine.
Btw: http://www.chucknorrisfacts.com/

PS2: Please DO answer my question, I am kinda confused =S
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition

Last edited by Flame_Phoenix : 04-27-2009 at 08:15 AM.
Flame_Phoenix is offline   Reply With Quote
Old 04-27-2009, 08:28 AM   #9
Pyrogasm
Lackadaisically Absent.
 
Pyrogasm's Avatar


Respected User
 
Join Date: Sep 2006
Posts: 4,522

Submissions (9)

Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)

Hero Contest - Fourth place

Send a message via ICQ to Pyrogasm Send a message via AIM to Pyrogasm Send a message via MSN to Pyrogasm Send a message via Yahoo to Pyrogasm
Default

You are correct. You do not technically need to null 'God', but all the same it's good practice and it surely can't hurt you to.
__________________
Quote:
Originally posted by Rising_Dusk
Your spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

The Spell Request Thread Done for, unless someone else wants to revive it...
It lasted a damn long time.

Please; Ask for Help Appropriately














Quote:
Originally posted by Kyrbi0
Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).
Quote:
Originally posted by Pyrogasm
Rome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.

Last edited by Pyrogasm : 04-27-2009 at 08:29 AM.
Pyrogasm is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 12:45 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services