On Aug 22, 2013, at 19:43 , Steve Mills <smi...@makemusic.com> wrote:

> On Aug 22, 2013, at 12:31:55, Thomas Wetmore <t...@verizon.net>
> wrote:
> 
>> Pre-allocation doesn't really matter as long as the re-allocations, whenever 
>> they occur, respect the capacity argument.
> 
> Sure they do. If you don't preallocate, but instead keep appending, and the 
> pointer needs to grow with every append, it *could* reallocate with every 
> append.

But that’s not how it’s typically implemented, you usually get some sort of 
exponential growth ( 2x or optimally something around 1.5x ), so amortized 
re-allocation cost on growth tends to be dominated by other factors.  Using the 
NSData variant of the algorithm I presented earlier and averaging over 4 runs 
each, I get a 2.5% difference.  Considering the factor 10-50 or more from the 
other optimizations, that’s pretty negligible, and was also significantly less 
than the variance between runs (so we would need a whole lot more runs to see 
whether the difference is actually real, chances are it isn’t).

Despite the fact that I am somewhat performance-obsessed, I tend to not 
pre-allocate.

Cheers,

Marcel


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to