Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFMutableStringRef creation question




On 2006 Jan 20, at 4:12 PM, John Stiles wrote:

Laurence Harris wrote:
Frankly, the whole mutable/immutable thing seems confusing at times. For
example, what's the point of specifying a capacity when creating a mutable
CF object? I've never been able to detect a performance different when
specifying a maximum capacity. Do the immutable variants offer any
advantages over their mutable counterparts?


For the same reasons that you'd specify a starting capacity when creating a hash table, or call reserve on a vector, etc. Everything will behave the same, but fewer trips into the allocator and fewer memcpy's. This might not be a significant win for some types of code, but for others it may be quite important.


Unlike most vector implementations, the maxLength field in CFStringCreateMutable() creates a hard bound upper limit. The mutable string can never be larger than the size passed in. If something happens that causes the size to be increased beyond the upper bound, an assertion is raised.


If you can guarantee that the string will never grow beyond the hard limit, then it can be a nice optimization. Otherwise, I consider it to be a nice trap that will appear when I least expect it.


Adin Hunter Baber email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: CFMutableStringRef creation question (From: Laurence Harris <email@hidden>)
 >Re: CFMutableStringRef creation question (From: John Stiles <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.