+dataWithCapacity:some_capacityThe docs note that this doesn't necessarily pre-allocate the given capacity.
Which is exactly why I said, in the very same sentence, "to guarantee it has the capacity (but not necessarily allocated yet)".
That's why you then call -setLength:, which writes out the entire length you specify, and so *has* to allocate the memory (because it fills any extra bytes with zeroes) - otherwise it isn't writing out the full length asked for.
In a nutshell, there's no way to "lock" the underlying bytes of NSMutableData
We weren't talking about locking them - the OP was asking about knowing when it would need to allocate new memory. If you guarantee the capacity and force it to be allocated yourself, then you can track any data you put in yourself to know when you're going to need another allocation to cope with data to be stored.
-- Jason Teagle _______________________________________________ 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]
