Re: [NSMutableData resetDataRangeTo:(NSRange)range];
Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- Subject: Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- From: Carl Hoefs <email@hidden>
- Date: Mon, 14 Jul 2014 11:12:32 -0700
Okay, now if I want to insert 1024 bytes of new data at the beginning of a populated NSMutableArray, is there a better way than this:
NSMutableData *bigMData = ... // (approx 1MB of data);
int origlength = bigMData.length;
uint8_t *newBytesPtr = ...
. . .
// Shift contents over by 1024 bytes
[bigMData replaceBytesInRange:NSMakeRange(1024,origlength)
withBytes:bigMData.bytes
length:origlength];
// Add new contents to the beginning
[bigMData replaceBytesInRange:NSMakeRange(0,1024);
withBytes:newBytesPtr
length:1024];
This seems a bit messy.
-Carl
On Jul 12, 2014, at 1:51 PM, Matt Gough <email@hidden> wrote:
> 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