• 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: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 22 Sep 2010 14:55:23 +0200

Le 22 sept. 2010 à 14:46, Oleg Krupnov a écrit :

> Hi,
>
> I have a NSMutableArray and need to add a number of elements to it,
> and their quantity I know in advance (in fact, they come from another
> array).
>
> I think that if I add them one-by-one in a loop, the array will have
> to reallocate its internal memory frequently. This seems inefficient.
>
> I'd like to avoid this and instead have the array to re-allocate its
> memory only once to increment the capacity by the known value.
>
> I could use "arrayWithCapacity" creation method, but the array already
> exists. 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. Have anyone tested this?


Is this part of your code a bottleneck ? If not, use the simplest way (-addObjectsFromArray:) and don't bother with premature optimization.

-- Jean-Daniel




_______________________________________________

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>)

  • Prev by Date: Efficiently adding a bunch of items to an NSMutableArray
  • Next by Date: Re: What's the point of @properties?
  • Previous by thread: Efficiently adding a bunch of items to an NSMutableArray
  • Next by thread: Re: Efficiently adding a bunch of items to an NSMutableArray
  • Index(es):
    • Date
    • Thread