On 23 May 2012, at 1:41 PM, Jason Teagle wrote:
> Unless I'm missing something, if you use
...
> -initWithCapacity:some_capacity
>
> to guarantee it has the capacity (but not necessarily allocated yet) followed
> by
>
> -initWithLength:some_capacity
DO NOT DO THIS.
-init... is a one-time operation in Cocoa. The call is privileged to make
destructive initializations to the object, to assume that its initial state can
be ignored, and even to replace the object entirely. Subsequent -init... calls
will in turn assume they can make destructive initializations, and the object
will almost certainly (maybe not today, maybe not tomorrow, but soon, and for
the rest of its life) break.
I can't make assumptions about how NSMutableData is implemented, but I'd guess
that -initWithLength: would assume that its buffer pointer is uninitialized,
and discard the buffer it got from -initWithCapacity: without freeing it. And
that's the best case I can imagine.
— F
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]