Re: [NSMutableData resetDataRangeTo:(NSRange)range];
Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- Subject: Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- From: Matt Gough <email@hidden>
- Date: Sat, 12 Jul 2014 21:51:13 +0100
don’t you just want:
[bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0];
??
I am sure NSMutableData is well optimized for shunting its contents around internally.
Matt
On 12 Jul 2014, at 20:36, Carl Hoefs <email@hidden> wrote:
> Basically what I would like is an NSMutableData method like this:
>
> - (void)resetDataRangeTo:(NSRange)range
>
> Parameters
> range
> The range within the contents of the receiver to be considered the new contents.
>
>
> But, since that doesn't exist yet, is it safe to "shift" the contents in place of an NSMutableData? I'm trying to avoid having to copy the contents, which is > 1MB.
>
> In this example, I want to remove the leading 1024 bytes in a large NSMutableData:
>
> NSMutableData *bigData = ... // (approx 1MB of data);
>
> UInt64 byte_shift = 1024; // skip over first 1024 bytes
> UInt64 new_length = bigMutData.length-byte_shift;
> NSRange moveRange = NSMakeRange(0,new_length);
>
> [bigMutData replaceBytesInRange:moveRange
> withBytes:bigMutData.bytes+1024
> length:new_length];
> [bigMutData setLength:new_length];
>
> -Carl
>
> _______________________________________________
>
> 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
_______________________________________________
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