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 (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to