• 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: A Question on estimating +arrayWithCapacity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Question on estimating +arrayWithCapacity


  • Subject: Re: A Question on estimating +arrayWithCapacity
  • From: Graham Cox <email@hidden>
  • Date: Sat, 10 Jan 2009 01:11:22 +1100


On 10 Jan 2009, at 1:07 am, Steve Cronin wrote:

Folks;

Under some circumstances I'm not sure how big a mutable object might need be.
So is there any guidance on coming up with a value for capacity?


Assume for these cases that reasonable guesses range from say 2 - 5000...

I assume it's wasteful to just do a land grab with +arrayWithCapacity:5000
but I also assume that it's unnecessarily burdensome to do +arrayWithCapacity:2.


So is the 'best' +arrayWithCapacity:2500?

It feels a little like premature optimization, but I do have to provide a value in the code....
Thanks for any feedback!
Steve

This came up a while back and the consensus was: don't bother at all. Just use [NSMutableArray array];


Odds are you'll never notice any performance difference and you'll not be using more memory than you need.

--Graham


_______________________________________________

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


  • Follow-Ups:
    • Re: A Question on estimating +arrayWithCapacity
      • From: Ken Thomases <email@hidden>
References: 
 >A Question on estimating +arrayWithCapacity (From: Steve Cronin <email@hidden>)

  • Prev by Date: Re: Best way to handle this
  • Next by Date: A Data Object in Cocoa
  • Previous by thread: A Question on estimating +arrayWithCapacity
  • Next by thread: Re: A Question on estimating +arrayWithCapacity
  • Index(es):
    • Date
    • Thread