HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Another silly leak question

07-04-2009, 03:59 PM#1
Cheezeman
Hey dudes!
I was wondering if this function is ok
Collapse JASS:
function AllowedTargets takes unit target, unit caster returns boolean
    return IsPlayerEnemy( GetOwningPlayer( caster ), GetOwningPlayer( target ) )
endfunction

or if I have to do it the hard way
Collapse JASS:
function AllowedTargets takes unit target, unit caster returns boolean
    local player c_owner = GetOwningPlayer( caster )
    local player t_owner = GetOwningPlayer( target )
    local boolean bool = false
    if IsPlayerEnemy( c_owner, c_owner ) then
        set bool = true
    endif
    set c_owner = null
    set t_owner = null
    return bool
endfunction
07-04-2009, 04:07 PM#2
Hans_Maulwurf
Yeah it's ok. But looks like you could improve performance by makeing this an actual condition for the enum using globals. can you post the part of the code, where you use this function?
07-04-2009, 04:10 PM#3
Opossum
Nah that's fine. Players don't leak as they are created on map init and exist throughout the game.

I think you don't even have to null player variables... not sure about that though.

Edit: damn you moleman!
07-04-2009, 04:16 PM#4
Cheezeman
It's a shortened version of my AllowedTargets checker for a spell I'm making.
It includes Magic Immune, structures, mechanical and other types of units, but I didn't want to bother you with the rest.
I'm using GroupEnumUnitsInRange() function which requires a boolexpr, which in this case is Condition( function AllowedTargetsCaller ), and AllowedTargetsCaller() passes on GetFilterUnit and GlobalCaster to AllowedTargets, so I can rename them (easier to edit later, though not as optimized)
07-04-2009, 04:29 PM#5
Hans_Maulwurf
That's what i guessed. just wanted to say you could get rid of a function call with 2 parameters for every single unit, when you put caster in a global tempvariable and use AllowedTargets as the Condition directly. However if you use AllowedTargets as a costumisation setup function it's ok ofc.
07-04-2009, 09:52 PM#6
Blubb-Tec
Quote:
Originally Posted by Opossum
Nah that's fine. Players don't leak as they are created on map init and exist throughout the game.

I think you don't even have to null player variables... not sure about that though.

Edit: damn you moleman!

from what i know, they're so called "pseudo-handles", and therefor don't increase the handle-count or any reference-counter, AFAIK. meaning they cause no leak whenever they're created and not destroyed, because nothing new is actually created, and nulling them is not required either(since they're not ref-counted).
since 1.24 the new variable type "agent" also exists, which is similar to handle, but actually is the type handle excluding pseudo-handles(such as player), and only including reference-counted handles.
thats the explanation for that, i find it pretty interesting and useful to know :)
07-04-2009, 10:10 PM#7
grim001
You don't need to null local player variables.
07-06-2009, 05:07 PM#8
Cheezeman
Quote:
Originally Posted by grim001
You don't need to null local player variables.
Now that's interesting...
Thank you (gotta spread rep around before I can give to you)

Oh and kudus to Blubb-Tec for a good explenation
07-06-2009, 05:59 PM#9
Blubb-Tec
Quote:
Originally Posted by Cheezeman
Now that's interesting...
Thank you (gotta spread rep around before I can give to you)

Oh and kudus to Blubb-Tec for a good explenation

Quote:
Originally Posted by Blubb-Tec
[...] and nulling them is not required either(since they're not ref-counted). [...]

if we're picky, grim only repeated what I already stated :P
07-07-2009, 11:03 AM#10
Cheezeman
Well I'm kind of slow so I didn't understand what you wrote, until now.
07-07-2009, 01:00 PM#11
ToukoAozaki
Quote:
from what i know, they're so called "pseudo-handles", and therefor don't increase the handle-count or any reference-counter, AFAIK. meaning they cause no leak whenever they're created and not destroyed, because nothing new is actually created, and nulling them is not required either(since they're not ref-counted).
since 1.24 the new variable type "agent" also exists, which is similar to handle, but actually is the type handle excluding pseudo-handles(such as player), and only including reference-counted handles.
thats the explanation for that, i find it pretty interesting and useful to know :)

Rather than a pseudo-handle, player works similar to singleton for each players. Actually player extends agent, hence it is not a pseudo-handle. Reference counts would be meaningless since player objects consume 1 reference count themselves, though.
07-07-2009, 01:02 PM#12
Blubb-Tec
Quote:
Originally Posted by Cheezeman
Well I'm kind of slow so I didn't understand what you wrote, until now.

haha, nice :P