| 01-12-2009, 06:56 PM | #1 |
Im currently updating an old map i made, therefore i added some libraries as TimerUtils, Table ... i also added this minimal Version of CSSafety to Recycle Groups only since i got TimerUtils for Timers.... JASS:library CSSafety requires CSData //****************************************************************************************** //* //* CSSafety 15.2 //* ¯¯¯¯¯¯¯¯ //* Eventually, we also added a group stack, the justification is different though, there //* are just memory leak related issues when using DestroyGroup on groups that were handled //* by certain natives, thus it is good to recycle them. Replace CreateGroup with NewGroup //* and DestroyGroup with ReleaseGroup. //* //****************************************************************************************** //========================================================================================== globals private group array gT private integer gN = 0 private constant integer HELD=0x23429022 //use a totally random number here, the more improbable someone uses it, the better. endglobals //========================================================================================== //========================================================================================== function NewGroup takes nothing returns group if (gN==0) then set gT[0]=CreateGroup() else set gN=gN-1 endif call SetCSData(gT[gN],0) return gT[gN] endfunction //========================================================================================== function ReleaseGroup takes group g returns nothing if(g==null) then debug call BJDebugMsg("Warning: attempt to release a null group") return endif if (gN==8191) then debug call BJDebugMsg("Warning: group stack is full, destroying group!!") //stack is full, the map already has much more troubles than the chance of bug call DestroyGroup(g) else call GroupClear(g) if(GetCSData(g)==HELD) then debug call BJDebugMsg("Warning: ReleaseGroup: Double free!") return endif call SetCSData(g,HELD) set gT[gN]=g set gN=gN+1 endif endfunction endlibrary However i am not totally sure how i should convert the triggers of my map to use this correctly ...problems: JASS:// Example of Old Script set udg_TempGroup=GetUnitsOfPlayerMatching(p,BOOLEXPR_TRUE) set bj_wantDestroyGroup=true call ForGroupBJ(udg_TempGroup,function DoSomething) // //========================================= // New "Good !?" Script: local group g=NewGroup() call GroupEnumUnitsOfPlayer(g, p, BOOLEXPR_TRUE) //call DestroyBoolExpr(filter) this one is called in the "GetUnitsOfPlayerMatching"-BJ function, //However i dont think i need it because my BOOLEXPR_TRUE is a global i reuse all over the place.. !? call ForGroup(g,function DoSomething) call ReleaseGroup(g) set g=null //correct ? another question... is CSSafety still up to date for group recycling or is there a newer system ? |
| 01-12-2009, 07:52 PM | #2 |
Try making the group a struct member, only create a new one if the index's group is null, then use GroupClear when you call onDestroy. Don't destroy it. This is essentially the same as a group stack, without any extra implementation. |
| 01-12-2009, 07:59 PM | #3 |
well i this map groups are used widely in (and some of them are periodic aswell) gameplay triggers, were i dont have (and need) any structs. |
| 01-12-2009, 08:04 PM | #4 | |
Quote:
|
| 01-12-2009, 08:09 PM | #5 |
minus the g=null part. |
| 01-12-2009, 08:17 PM | #6 |
If i assume he won't use any more the function DestroyGroup, and use ReleaseGroup instead, set g= null is unneeded, no ? |
| 01-12-2009, 08:30 PM | #7 | |
Quote:
|
| 01-12-2009, 08:52 PM | #8 |
Why not just keep a global group? JASS:globals private group g = CreateGroup() endglobals ... call GroupEnumUnitsOfPlayer(g, p, BOOLEXPR_TRUE) call ForGroup(g,function DoSomething) //you could avoid calling ForGroup by doing your stuff in the GroupEnum filter call GroupClear(g) |
| 01-12-2009, 09:17 PM | #9 |
For triggers which are evaluate/executed only one time or little more it's overskilled imho, i mean we create a group for it but we don't really have the need. What about the null thing ? |
| 01-12-2009, 09:25 PM | #10 |
Since it's just a reference of a global group, you don't need to null it. |
| 01-12-2009, 10:28 PM | #11 | |
Quote:
|
| 01-12-2009, 10:36 PM | #12 |
Just to be more clear, for a local trackable variable, we don't use to null it, because the trackable will be never destroyed, right ? I mean a handle in general which is never destroyed, we don't need to null the local variable reference ? |
| 01-12-2009, 10:41 PM | #13 |
A handle which is never destroyed can never have its handle index recycled, so no need to null it. |
| 01-12-2009, 10:44 PM | #14 | |
Quote:
|
