Re: NSMutableData capacity
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