• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableData capacity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSMutableData capacity
      • From: Thomas Davie <email@hidden>
References: 
 >NSMutableData capacity (From: Andreas Grosam <email@hidden>)
 >Re: NSMutableData capacity (From: Jason Teagle <email@hidden>)
 >Re: NSMutableData capacity (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: Re: group row custom drawing nstableview
  • Next by Date: Re: NSMutableData capacity
  • Previous by thread: Re: NSMutableData capacity
  • Next by thread: Re: NSMutableData capacity
  • Index(es):
    • Date
    • Thread