Re: NSMutableData capacity
Re: NSMutableData capacity
- Subject: Re: NSMutableData capacity
- From: Jason Teagle <email@hidden>
- Date: Thu, 24 May 2012 06:02:33 +0100
- Organization: Organised Bytes Software
+dataWithCapacity:some_capacity
The 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@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