Tuesday, November 29, 2011

[android-developers] iterator blues

I'm looking at the Best Practices section of "Beginning Android
Games", and it says:

"Don't use iterators, as they create new objects."

Can someone help me understand?

The reason I ask is because I'm seeing performance issues with this
method:

public static void burnfire() {
for (final Iterator<Particle> i = particles.iterator();
i.hasNext();) {
final Particle p = i.next();
p.move();
p.timeleft--;

if (p.timeleft == 0) {
i.remove();
}
}

}

The method just traverses a linked list and moves some particles. Are
objects being created there?

How can I make that faster?

Thanks.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate