• 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: Efficiently adding a bunch of items to an NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Efficiently adding a bunch of items to an NSMutableArray


  • Subject: Re: Efficiently adding a bunch of items to an NSMutableArray
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 22 Sep 2010 14:41:49 -0500

On Sep 22, 2010, at 05:46, Oleg Krupnov wrote:

> It seems that the -addObjectsFromArray: method may be what I
> need, but the docs do not make it clear if it's internally optimized
> to do only a single memory re-allocation.

I'll add my two cents: you should almost always use the method that directly describes the operation you're trying to perform at a high level (-addObjectsFromArray:, in this case).  If there's a way that you could imagine breaking the high-level operation down into low-level operations, then that same technique is available to the implementors of the high-level routine.  Plus, they may have techniques available to them that you don't -- they have access to the internals, they can put more resources into optimization, etc.  By choosing the high-level operation, you give the implementation the greatest freedom to take advantage of advanced techniques.  If you choose the low-level techniques, you curtail the possibilities.

Also, the high-level approach will be less code, less error-prone, easier to read and understand, etc.

It's almost always the right choice.

And, as others have said, you're probably optimizing prematurely.  So, all of the other considerations probably swamp any benefit from caring about the performance of this single operation.

Regards,
Ken

_______________________________________________

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: 
 >Efficiently adding a bunch of items to an NSMutableArray (From: Oleg Krupnov <email@hidden>)
 >Re: Efficiently adding a bunch of items to an NSMutableArray (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSTableView display issue
  • Next by Date: Re: What's the point of @properties?
  • Previous by thread: Re: Efficiently adding a bunch of items to an NSMutableArray
  • Next by thread: Question about UITableView and loading some XML
  • Index(es):
    • Date
    • Thread