Questions on run-time

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Since I am currently coding a new threat system, I was wondering which of the following is the fastest:

1) Having a unit array (and a maxindex integer) and looping through the units.
--> this also comes with the advantage of having perfect control over all the values assigned, so I would prefer this, if there are no big differences in run-time.

2) Having a group, copying it and using a loop with the FirstOfGroup(), GroupRemoveUnit() method.

3) Using ForGroup()


Also, I was wondering if IsUnitInGroup() is faster than looping through a unit array or group?


Does anyone know this?
 

SerraAvenger

Cuz I can
Reaction score
234
Also, I was wondering if IsUnitInGroup() is faster than looping through a unit array?

AFAIK, IsUnitInGroup uses binary search and is thus faster unless you do binary search yourself.
Otherwise it's just a constant factor so I don't care :p
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Does nobody know this? I think it's a pretty common problem and I am sure someone has tried this before.


Another question:
is
JASS:

FirstOfGroup(G) == null

even a stable way to find out wether the group is empty? I mean ... do groups instantly clean null references?
 

jwallstone

New Member
Reaction score
33
Yes, FirstOfGroup(G) == null will tell you whether it is empty.

Regarding 2 and 3: if you copy a group, you'll be running a ForGroup function anyway. It's faster just to use ForGroup.

Regarding 1: I would think that using an array is faster for accessing units and looping through them, but the add/remove logic would have to be implemented by you, and might be slower since it's in a script rather than native. So, if you are always taking units in and out of this array, use a ForGroup with a group. If it's a more static collection of units, the array will be faster.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Thanks for the answers. I think I will stick to the way I have it now. Using Unit Arrays where it is useful to have "better" control over all spots (i.e. to detect removed units) and avoiding GroupAddGroup.
 

Viikuna

No Marlo no game.
Reaction score
265
FirstOfGroup(G)==null only fails if you keep those units in group for some time and that first of group unit is removed from the game ( by dying, or remove unit )

Basicly, if you add unit to group, and unit gets removed from the game, it doesnt get removed from the group and leaves this ghost reference to group, which then returns null.

There is this nice GroupRefresh function by Griffen, which can be used to counter this. Also, if you use that FirstOfGroup(G)==null check just after GroupEnum, it works just fine.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
FirstOfGroup(G)==null only fails if you keep those units in group for some time and that first of group unit is removed from the game ( by dying, or remove unit )
So the new empty spot is not filled up at once, isn't it,but after a certain time?

Basicly, if you add unit to group, and unit gets removed from the game, it doesnt get removed from the group and leaves this ghost reference to group, which then returns null.
This is contradictory. So removed units do NOT get cleared from groups ever? (Except with GroupClear(), of course)

There is this nice GroupRefresh function by Griffen, which can be used to counter this. Also, if you use that FirstOfGroup(G)==null check just after GroupEnum, it works just fine.
Hmm ... Since I only use groups temporarily in my system and clear the group after that, it should be fine, then.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top