H
Helge Richter
I'm trying to optimize my application for speed.
Basically what I'm doing is adding Elements which need to be informed of
a Tick (a specifc amount of time) to an Vector and remove them when
they're finished.
My First aproach was:
for (int i = 0; i < tickables.size(); i++) {
tickable t = (tickable) tickables.elementAt(i);
t.tick(timediff, this);
if (t.canBeRemoved())
tickables.remove(t);
}
}
This obviously skips a tickable when the one in front of it was removed.
What's the best thing to do in this case?
Reduce i by one and check if I'm still within the Vector-bounds?
Do a clone of the Vector and only remove from the "real" vector?
I'll want to do that during a paint method, so I'm trying to make it as
cpu friendly as possible..
Thx for your help...
Basically what I'm doing is adding Elements which need to be informed of
a Tick (a specifc amount of time) to an Vector and remove them when
they're finished.
My First aproach was:
for (int i = 0; i < tickables.size(); i++) {
tickable t = (tickable) tickables.elementAt(i);
t.tick(timediff, this);
if (t.canBeRemoved())
tickables.remove(t);
}
}
This obviously skips a tickable when the one in front of it was removed.
What's the best thing to do in this case?
Reduce i by one and check if I'm still within the Vector-bounds?
Do a clone of the Vector and only remove from the "real" vector?
I'll want to do that during a paint method, so I'm trying to make it as
cpu friendly as possible..
Thx for your help...