Jesus4Lyf
Good Idea™
- Reaction score
- 396
>This is especially useful as GroupEnum will cause a group to leak even if it is destroyed, so simply using one global group will create only one leak (am I correct in that the leak is only one per group, Jesus4Lyf?).
Yeah. Once a group has an enum called for it, destroying it will leak (as per this tut). It seems that each enum overwrites the data from the previous one that would otherwise leak, or something.
I didn't look too deeply as to whether the size of the leak is difference based on how many enums you called, I found the point simply to be that you should recycle groups...
-->
(I have not syntax checked it.)
>Could somebody explain to me why looping trough a group with FirstOfGroup(group) is deprecated?
It is deprecated in different circumstances for different reasons. In this situation, it is deprecated due to efficiency. The tutorial explains that in other situations, ghost references can cause a FirstOfGroup loop to terminate early (if the group was not created immediately before the FoG loop occurred).
>It should just be as simple as stating that if Create/Destroy group functions are used, that the normal handle nulling rules still apply.
Hm, I'll add that at some point I guess.
Yeah. Once a group has an enum called for it, destroying it will leak (as per this tut). It seems that each enum overwrites the data from the previous one that would otherwise leak, or something.
I didn't look too deeply as to whether the size of the leak is difference based on how many enums you called, I found the point simply to be that you should recycle groups...
JASS:
function CopyGroup takes group g returns group //This function was NOT written by me, I've got it from a tutorial on wc3c.net
set bj_groupAddGroupDest = CreateGroup()
call ForGroup(g, function GroupAddGroupEnum)
return bj_groupAddGroupDest
endfunction
function CountLivingHeroesOfForce takes force team returns integer
local integer count = 0
local unit u
local group g
set g = CopyGroup(Heroes)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if IsPlayerInForce(GetOwningPlayer(u), team) and GetWidgetLife(u) > 0.045 then
set count = count + 1
endif
call GroupRemoveUnit(g, u)
endloop
call DestroyGroup(g)
return count
endfunction
-->
JASS:
scope CountLivingHeroesOfForceScope
globals
private integer Count
private force Team
private unit Enum
endglobals
private function CountLivingHeroesOfForceEnum takes nothing returns nothing
set Enum=GetEnumUnit() // Could be a local, but you'd need to null it then.
if IsPlayerInForce(GetOwningPlayer(Enum),Team) and GetWidgetLife(Enum)>.405 then // You'd put 0.045.
set Count=Count+1
endif
endfunction
function CountLivingHeroesOfForce takes force team returns integer
set Count=0
set Team=team
call ForGroup(Heroes,function CountLivingHeroesOfForceEnum)
return Count
endfunction
endscope
(I have not syntax checked it.)
>Could somebody explain to me why looping trough a group with FirstOfGroup(group) is deprecated?
It is deprecated in different circumstances for different reasons. In this situation, it is deprecated due to efficiency. The tutorial explains that in other situations, ghost references can cause a FirstOfGroup loop to terminate early (if the group was not created immediately before the FoG loop occurred).
>It should just be as simple as stating that if Create/Destroy group functions are used, that the normal handle nulling rules still apply.
Hm, I'll add that at some point I guess.