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 > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-02-2006, 08:10 AM   #16
vile
n00b map maker
 
Join Date: Jul 2005
Posts: 599

Submissions (5)

vile will become famous soon enough (60)vile will become famous soon enough (60)vile will become famous soon enough (60)

Send a message via ICQ to vile Send a message via AIM to vile Send a message via MSN to vile
Default

It usually happens with a wide variety of spells that are using timers. Try to make a map that uses that and see for yourself, I have no reason to put false facts here.
__________________
Check out my maps:
Age of Myths
Deadly Games
Magic & Steel New Project is kicking in!

TEASER TRAILER
vile is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-04-2006, 01:51 AM   #17
emjlr3
Rehabbing
 
emjlr3's Avatar
 
Join Date: Jun 2005
Posts: 1,386

Submissions (14)

emjlr3 is a jewel in the rough (151)emjlr3 is a jewel in the rough (151)

Mapping Contest First Place

Send a message via AIM to emjlr3 Send a message via MSN to emjlr3
Default

so...in conclusion...always pause timers before destroying them

wait before setting to null

and this should stop any bugs?
__________________
emjlr3 is offline   Reply With Quote
Old 04-04-2006, 03:40 AM   #18
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

why wait before setting to null? that is not bullet proof unless the wait is very big (thus it will still consume memory during the wait) and just using arguments fixes the problems
__________________
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-04-2006, 04:44 AM   #19
emjlr3
Rehabbing
 
emjlr3's Avatar
 
Join Date: Jun 2005
Posts: 1,386

Submissions (14)

emjlr3 is a jewel in the rough (151)emjlr3 is a jewel in the rough (151)

Mapping Contest First Place

Send a message via AIM to emjlr3 Send a message via MSN to emjlr3
Default

Quote:
Originally Posted by Vexorian
why wait before setting to null? that is not bullet proof unless the wait is very big (thus it will still consume memory during the wait) and just using arguments fixes the problems

arguments? im lost, english plz
__________________

Last edited by emjlr3 : 04-04-2006 at 04:44 AM.
emjlr3 is offline   Reply With Quote
Old 04-04-2006, 06:05 AM   #20
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

- Setting timers to null is a no no
- Half the tutorial is other methods for fixing that leak that work
- Vex suggests the function wrappers (variables as function arguments instead of the usual locals)
- I will spell this out above

Last edited by PipeDream : 04-04-2006 at 06:06 AM.
PipeDream is offline   Reply With Quote
Old 04-05-2006, 08:59 AM   #21
Anitarf
Procrastination Incarnate


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

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

You still destroy the location instead of returning it in the last example. Also, while correct, this isn't the most optimized:
Collapse JASS:
function SomeFunc takes nothing returns location
    local integer iunitloc = H2I(GetUnitLoc(GetTriggerUnit())
    //Do stuff with iunitloc
    return I2L(iunitloc) //Don't forget to remove
endfunction
I would use something like this:
Collapse JASS:
function SomeFunc takes nothing returns location
    local location loc = GetUnitLoc(GetTriggerUnit()
    local integer iunitloc = H2I(loc)
    //Do stuff with loc
    set loc = null
    return iunitloc
    return null
endfunction
This way, you don't have to call I2L at all, so you save yourself some function calls. But this isn't such a big issue, good job on the tutorial.
__________________
Anitarf is offline   Reply With Quote
Old 04-05-2006, 10:03 AM   #22
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Inline the return bug: Good idea. Changed.

Last example- Just giving a mix. But you're right, no point to not using set to null if you intend to remove. I'll change it.

Thanks.
PipeDream is offline   Reply With Quote
Old 04-11-2006, 12:10 PM   #23
Blackroot
User
 
Join Date: Apr 2006
Posts: 260

Blackroot will become famous soon enough (40)Blackroot will become famous soon enough (40)

Spell Making Session 14 Winner

Default

Is the overhead from wrappers worth nulling a single return value? It almost seems like a tradeoff. Slow down the shortrun to assist in the longrun, or vice versa ~,~.

Definantly interesting code here, I might update my version of Local Vars to use wrappers.

Also, one of your examples leaks :P
Collapse JASS:
function MyTriggerAction takes nothing returns nothing
    local location unitloc = GetUnitLoc(GetTriggerUnit())
    //Do stuff
    call RemoveLocation(unitloc)
    set unitloc = null
endfunction

You used trigger unit, but it will leak that call.

Collapse JASS:
function MyTriggerAction takes nothing returns nothing
 local unit u  = GetTriggerUnit()
 local location unitloc = GetUnitLoc(u)

 set u = null
 //Do stuff
 call RemoveLocation(unitloc)
 set unitloc = null
endfunction

Not really a big problem, but it might be a good idea to update it :P.

Last edited by Blackroot : 04-11-2006 at 12:17 PM.
Blackroot is offline   Reply With Quote
Old 04-13-2006, 05:09 AM   #24
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Hm. I guess I did not explain this adequately. That reference count increments only when you assign the object to a variable of type handle. Since the unit of GetTriggerUnit() is never assigned there is no leak.

I recommend the set to null method whenever it is practical. When it isn't, for example for timers or when you must return, then function wrappers are the fallback.

-Added section "Globals and GUI"

Last edited by PipeDream : 04-13-2006 at 05:11 AM.
PipeDream is offline   Reply With Quote
Old 04-13-2006, 04:11 PM   #25
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

oh come on , what's the problem with you? how could you people still not get it?

Collapse JASS:
function MyTriggerAction takes nothing returns nothing
    local location unitloc = GetUnitLoc(GetTriggerUnit())
    //Do stuff
    call RemoveLocation(unitloc)
    set unitloc = null
endfunction

Does not leak anything at all.

There is no need to set things to null when they are not in local variables.

If you only needed to use triggering unit to get its location then it is all right to use it directly instead of using variables.

An extra function call is always better than a memory leak.




Anitarf : this would be the most optimized:

Collapse JASS:
function SomeFunc takes nothing returns location
    local integer iunitloc = H2I(GetUnitLoc(GetTriggerUnit())
    //Do stuff with loc
    set loc = null
    return iunitloc
    return null
endfunction


But most of the times it is better to use arguments, specially when it is a function already so it won't add any extra function call. Return bug is slow, really slow


Collapse JASS:
function GetSomeLoc takes location loc returns location
  //do something
  set loc= //whatever the result is
  //do more
 return loc
endfunction

The way to call the function would be GetSomeLoc(null)

Of course, calling things with null as argument doesn't have much sense, but it would be the perfect solution, seriously.

Of course most of the times you can take advantage of one of the arguments

Collapse JASS:
function GetSomeLoc takes location loc returns location
 local real x=GetLocationX(loc)
 local real y=GetLocationY(loc)

  set loc= Location(x+2,y+4)
 return loc
endfunction


Creates a point based on the given point.

A very intelligent version of that would be:

Collapse JASS:
function GetSomeLoc takes location loc returns nothing
 local real x=GetLocationX(loc)
 local real y=GetLocationY(loc)

  call MoveLocation(loc,x+2,y+4)
 return loc
endfunction

That way instead of creating a point you move the given one and you don't have to care about leaks and that crap.

And you could use a CopyLocation to make that function able to work on many situations

Collapse JASS:
function CopyLocation takes location loc returns location
    return (Location(GetLocationX(loc),GetLocationY(loc)) )
endfunction


have fun
__________________
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-25-2006, 02:38 PM   #26
blu_da_noob
Nonchalant
 
blu_da_noob's Avatar


Respected User
 
Join Date: Mar 2006
Posts: 1,933

Submissions (2)

blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)

[Quicksilver #2] - 2nd Place[Quicksilver#1] 1st place

Send a message via MSN to blu_da_noob
Default

Wouldn't another solution to the 'don't null local timer variables' bug be to use a global variable to store them (temporarily) instead. Bj's could be used for easy importing. For example bj_crippledTimer is a timer array that is only used up to the highest player index, meaning that it is open for use at indexes higher than that.

Collapse JASS:
function TimerCallback takes nothing returns nothing
    local integer i
    local string s

    set bj_crippledTimer[1337] = GetExpiredTimer()
    set s = I2S(H2I(bj_crippledTimer[1337]))
    set i = GetStoredInteger(Cache(),s,"integer")
    //etc etc
endfunction

That would relieve the problem, or so I think. Anyone care to confirm/correct?

Last edited by blu_da_noob : 04-25-2006 at 02:38 PM.
blu_da_noob is offline   Reply With Quote
Old 04-25-2006, 06:45 PM   #27
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Yes, that is what the stack stuff is intended to do. I don't want to advocate anything simpler because you'll lose foolproof multiinstanceability.
__________________
PipeDream is offline   Reply With Quote
Old 05-25-2006, 04:17 PM   #28
Anitarf
Procrastination Incarnate


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

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 Vexorian
Anitarf : this would be the most optimized:

Collapse JASS:
function SomeFunc takes nothing returns location
    local integer iunitloc = H2I(GetUnitLoc(GetTriggerUnit())
    //Do stuff with loc
    set loc = null
    return iunitloc
    return null
endfunction
You forgot to delete "set loc = null", since it seems you want to ommit the local location variable. The problem with that is with the "//Do stuff with loc" part, since you would have to use I2L constantly; you usualy don't do that much operations with locations, but what about unit groups, timers...? Seems more optimized to just declare another local variable and then null it.
__________________
Anitarf is offline   Reply With Quote
Old 06-14-2006, 05:43 PM   #29
BertTheJasser
xyzi - our universe
 
BertTheJasser's Avatar
 
Join Date: May 2005
Posts: 742

Submissions (2)

BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)

Default

You actually must nullify the loc var or it will leak in that function. The 2 return lines will return exactly the same as the actually loc is(and it is still the same location), but the function is leak free. The function that calls (in this case) "SomeFunc" has to REMOVE the location that is returned by it, as it still exists. Same with unitgroups, triggers,triggeractions etc.
__________________
Note: Bye... I had a lot of fun here!
Special thanks to Vexorian who helped me learn jass, the real jass and always helped me when problems occured, I would call him somehow my mentor. Pipedream, who made amazing Grimoire and helped me acclerating my map (currently at 99% finished, no developement atm).

Vote for Linux Ports in general of Blizzard products: http://www.PetitionOnline.com/ibpfl/

Last edited by BertTheJasser : 06-14-2006 at 05:45 PM.
BertTheJasser 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 02:16 AM.


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

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