In summary, the existence of fast enumeration does nothing for
existing enumeration technologies and if you have to support
10.4 (as I do) you simply can't use it unless you fork your code.

My solution, in the few cases where performance is paramount,
has been to essentially roll my own fast enumeration. For very
large arrays (thousands of objects) I'll get blocks of objects
in batching using [NSArray getObjects:range:], process those in
a tight C loop, and then get another batch.

The for (in) construct is by far the most optimized general purpose way to work with any of the collections in Cocoa on 10.5, 10.6, and iPhone OS. It's also polymorphic, so custom collection subclasses can fine tune the behavior.

If you have to hand roll your own, either for 10.4, or some specialized case, your best bet is to use -getObjects: into a local buffer. gcc supports variable length arrays, and that's the fastest way to marshall these batches temporarily. You'll want to be very careful to do length checks to not overrun your stack, and limit the size. If you have somewhere between 256 & 512 objects, give or take, you'll have to malloc a temporary id* Overflowing the stack is not pretty.

- Ben



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to