• 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: Mutable arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutable arrays


  • Subject: Re: Mutable arrays
  • From: Jason Stephenson <email@hidden>
  • Date: Mon, 20 Oct 2008 11:02:43 -0400

DKJ wrote:
Since mutable arrays and dictionaries expand as required when new objects are added, when should one use -initWithCapacity: methods?

I have used it when my program can figure out roughly how many items will be in the mutable object to begin with.


Say my program is pulling some data from a database table and there are 64 rows in the table when I go to initialize a NSMutableArray to hold the data rows from the table. In that case, I'd use -initWithCapacity: to indicate that there are about to be 64 objects inserted into the array.

If my program can't know how many items will go in the object at the start, then I won't bother using it.

I've never checked if it speeds things up or not, but it seems like the time to use it when you know how much data you'll be putting in the object at the start.

Jason
_______________________________________________

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: 
 >Mutable arrays (From: DKJ <email@hidden>)

  • Prev by Date: Re: Mutable arrays
  • Next by Date: lockFocus error
  • Previous by thread: Re: Mutable arrays
  • Next by thread: Detecting system preference for trackpad zooming.
  • Index(es):
    • Date
    • Thread