• 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: Jens Alfke <email@hidden>
  • Date: Thu, 24 May 2012 08:36:10 -0700

On May 24, 2012, at 12:43 AM, Andreas Grosam wrote:

> While I experienced, that this approach is much faster than appending bytes using NSMutableData methods, the above implementation could be still better when having something like a -capacity  method for a NSMutableData object which is the size of the raw memory buffer of the underlaying allocator, and not some potential "max size" or "hint".

So don't worry about the internal implementation of the capacity of the data object; just set its .length explicitly to what you want, and then keep track yourself of how many bytes of it you're actually using.

So if you want a capacity of 1MB, call data.length = 1024*1024. Keep your own 'actualLength' property, or a pointer to the end of the mutableBytes, or whatever. When you run out of that, increase data.length some more.

Or as I said before, just keep your own malloc block instead of an NSData. Because really, NSMutableData is just a very thin OOP wrapper around malloc/realloc/free.

—Jens
_______________________________________________

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


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

  • Prev by Date: Re: Multiple Inheritance
  • Next by Date: Re: Multiple Inheritance
  • Previous by thread: Re: NSMutableData capacity
  • Next by thread: Re: NSDocument autosave doesn't show as edited
  • Index(es):
    • Date
    • Thread