HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

null or Condition(function ReturnTrue) ?

02-05-2008, 09:33 PM#1
XieLong
I've got a question, which I hope you can answer me: Many JASS functions (as the GroupEnumUnits... and TriggerRegisterPlayerUnitEvent) take a booleanexpr as a filter. But when I want to get all units, is it better to only give the parameter null or use this
Collapse litte boolexpr:
function ReturnTrue takes nothing returns boolean
    return true
endfunction
.
.
.
call TriggerRegisterPlayerUnitEvent( gg_trg_UnitDeath, Player(0), EVENT_PLAYER_UNIT_DEATH, Condition(function ReturnTrue) )
The reason for my question is the following: I heard that the frequently usage of null as a boolexpr cause WC3 produce leaks (no idea why) but on the other hand with ReturnTrue there's all the time a new boolexpr object that have to be destroyed... Please explain this behaviour and the optimal method for avoiding any of these leaks to me.
The point is also that I don't get the whole boolepr thing... there's a boolexpr object, but at which time? When I call Condition(function ...) or when it's evaluated? I don't understand that so it would be very kind of you to explain me the whole problem. Thanks :)
02-05-2008, 11:28 PM#2
Toadcop
Quote:
there's all the time a new boolexpr object that have to be destroyed...
this is false =) you don't need. it get "cached" (like strings)
and yes null (as condition for some functions) seems to cause leaks...
02-05-2008, 11:41 PM#3
cohadar
I use null all the time and I never noticed it?
At least it did not increase handle count.

Meh, if it is only leaking boolexpr memory (4 bytes) then seriously who cares.
02-06-2008, 12:48 AM#4
Vexorian
null seems to cause silly stuff not just a leak.

I prefer a BOOLEXPR_TRUE variable.
02-06-2008, 02:42 AM#5
Pyrogasm
As to what Vexorian said:
Collapse JASS:
library BoolLib initializer Init
    globals
        boolean BOOLEXPR_TRUE
        boolean BOOLEXPR_FALSE
    englobals

    private function True takes nothing returns boolean
        return true
    endfunction

    private function False takes nothing returns boolean
        return false
    endfunction

    private function Init takes nothing returns nothing
        set BOOLEXPR_TRUE = Condition(function True)
        set BOOLEXPR_FALSE = Condition(function True)
    endfunction
endlibrary
I believe it's also part of CSSafety...?
02-06-2008, 12:43 PM#6
Vexorian
I doubt so, but I think I once made that think.
02-06-2008, 01:07 PM#7
moyack
Quote:
Originally Posted by Pyrogasm
As to what Vexorian said:
Collapse JASS:
library BoolLib initializer Init
    globals
        boolexpr BOOLEXPR_TRUE
        boolexpr BOOLEXPR_FALSE
    englobals

    private function True takes nothing returns boolean
        return true
    endfunction

    private function False takes nothing returns boolean
        return false
    endfunction

    private function Init takes nothing returns nothing
        set BOOLEXPR_TRUE = Condition(function True)
        set BOOLEXPR_FALSE = Condition(function False)
    endfunction
endlibrary
I think this is what you mean.
02-06-2008, 01:48 PM#8
cohadar
Quote:
Originally Posted by Vexorian
null seems to cause silly stuff not just a leak.

I prefer a BOOLEXPR_TRUE variable.

What silly stuff?
02-07-2008, 12:05 AM#9
Pyrogasm
You didn't fix my "englobals", Moyack. :P
02-07-2008, 07:05 PM#10
XieLong
Okay, thank you all very much :)
02-09-2008, 05:23 PM#11
Themerion
Quote:
What silly stuff?

Please?
02-09-2008, 07:05 PM#12
grim001
Quote:
Originally Posted by cohadar
What silly stuff?

Handle count doesn't go up, it just causes memory usage to increase and eventually slows the game down if you make heavy usage of GroupEnum.
02-09-2008, 07:38 PM#13
cohadar
I don't.
I guess that is why I never noticed it...