Re: [NSMutableData resetDataRangeTo:(NSRange)range];
Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- Subject: Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- From: Mike Abdullah <email@hidden>
- Date: Tue, 15 Jul 2014 09:45:12 +0100
On 15 Jul 2014, at 00:32, Jens Alfke <email@hidden> wrote:
>
> On Jul 14, 2014, at 1:07 PM, Carl Hoefs <email@hidden> wrote:
>
>> modifiableData = [ NSMutableData dataWithData: [ external call that gives me an NSData ] ];
>
> It’s shorter and more idiomatic to just say
> modifiableData = [external mutableCopy];
> (plus an autorelease if you’re not using ARC)
>
>> Will get it working first, and if there's a performance panic, perhaps something can be done (but I extremely doubt it).
>
>
> Well, the most optimal thing to do would be to create an empty NSMutableData of the correct size, then use memcpy to copy in the correct pieces from the original NSData and whatever other sources there are. That will save you some unnecessary copies and possibly realloc calls.
Another possibility is to use dispatch_data. Rather than copy bytes around to assemble them into a contiguous buffer, your use case might be just as well suited to dispatch_data’s approach of tying together various non-contiguous buffers.
_______________________________________________
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