• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is checking -count worth it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is checking -count worth it?


  • Subject: Re: Is checking -count worth it?
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 24 Jul 2008 10:56:54 -0700


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 (email@hidden)

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:

This email sent to email@hidden

References: 
 >Is checking -count worth it? (From: Steve Cronin <email@hidden>)
 >Re: Is checking -count worth it? (From: Jens Alfke <email@hidden>)
 >Re: Is checking -count worth it? (From: Matthew Schinckel <email@hidden>)

  • Prev by Date: Re: Sent Actions, Delegates, Outlets
  • Next by Date: Newb Question re Messaging and Return Values
  • Previous by thread: Re: Is checking -count worth it?
  • Next by thread: Help on Menu Item
  • Index(es):
    • Date
    • Thread