On 24 Jul '08, at 12:02 AM, Matthew Schinckel wrote:

Am I better off in general (ie, adding objects, removing objects, etc) using an NS(Mutable)Set instead of an NSArray, if I don't need sorting and duplicate items?

As always, it depends. For the most part, sets are faster because they're implemented using hash tables. This makes them scale much better for locating or removing items. But they do have a bit more fixed overhead per operation, since they have to compute the hash code of the object. So for very small collections, an array might be faster. It's also faster to just append an item to an array than to add it to a set.

Sets also have somewhat higher memory overhead (3 or 4 times sizeof(id) per item, as opposed to just sizeof(id)).

In reality none of this will matter 99% of the time. It's only something you want to pay attention to when you're pretty sure that particular collection will grow huge or be accessed zillions of times.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to