Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Mike Abdullah
On 15 Jul 2014, at 00:32, Jens Alfke j...@mooseyard.com wrote: On Jul 14, 2014, at 1:07 PM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: modifiableData = [ NSMutableData dataWithData: [ external call that gives me an NSData ] ]; It’s shorter and more idiomatic to just say

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Carl Hoefs
On Jul 15, 2014, at 1:45 AM, Mike Abdullah mabdul...@karelia.com wrote: 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

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Jens Alfke
On Jul 15, 2014, at 9:50 AM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Awesome! I had been wondering if this concept existed in Cocoa, didn't see it in the NSData docs. It's sort of like using iovec structs with readv/writev for sockets. I would primarily use the

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-15 Thread Kyle Sluder
On Jul 15, 2014, at 10:20 AM, Jens Alfke j...@mooseyard.com wrote: On Jul 15, 2014, at 9:50 AM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Awesome! I had been wondering if this concept existed in Cocoa, didn't see it in the NSData docs. It's sort of like using iovec structs with

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
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

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Mike Abdullah
On 14 Jul 2014, at 19:12, Carl Hoefs newsli...@autonomy.caltech.edu wrote: 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: Yes. [bigMData replaceBytesInRange:NSMakeRange(0,0)

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Ben Kennedy
On 14 Jul 2014, at 11:12 am, Carl Hoefs newsli...@autonomy.caltech.edu wrote: 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: Sure; why not just do [bigMData replaceBytesInRange:NSMakeRange(0,0)

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 11:22 AM, Mike Abdullah mabdul...@karelia.com wrote: [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr length:1024]; On Jul 14, 2014, at 11:23 AM, Ben Kennedy b...@zygoat.ca

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Ben Kennedy
On 14 Jul 2014, at 11:30 am, Carl Hoefs newsli...@autonomy.caltech.edu wrote: [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr length:1024]; Wow, that's damn clever! My thinking is so clunky. It never would have occurred to me that NSMutableData could expand (0,0) into

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 11:35 AM, Ben Kennedy b...@zygoat.ca wrote: On 14 Jul 2014, at 11:30 am, Carl Hoefs newsli...@autonomy.caltech.edu wrote: [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr length:1024]; Wow, that's damn clever! My thinking is so clunky. It never

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 11:48 AM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Yes, I guess it's the semantics that threw me. I was attempting to insertBytesInRange not replaceBytesInRange, so I had it in my mind that the one couldn't do the other. But that's the whole purpose of the

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 11:54 AM, Jens Alfke j...@mooseyard.com wrote: On Jul 14, 2014, at 11:48 AM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Yes, I guess it's the semantics that threw me. I was attempting to insertBytesInRange not replaceBytesInRange, so I had it in my mind that

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 12:15 PM, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Okay, 1 last question on this. Is there a way to promote-in-place an NSData object into an NSMutableData object? -becomeMutable or some such? I'm trying to avoid copying megabytes of data/sec if it's avoidable.

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Gary L. Wade
The reason you can't do exactly what you're asking is because there may be other owners of the immutable object. Since NSMutableData is a subclass of NSData, you should ask yourself where you're creating the object and try creating it from the start as mutable, and also if there are owners of

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Carl Hoefs
On Jul 14, 2014, at 12:57 PM, Gary L. Wade garyw...@desisoftsystems.com wrote: where you're creating the object On Jul 14, 2014, at 12:53 PM, Jens Alfke j...@mooseyard.com wrote: If you’re the one creating the NSData object in the first place, can you create it as an NSMutableData?

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Jens Alfke
On Jul 14, 2014, at 1:07 PM, Carl Hoefs newsli...@autonomy.caltech.edu 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

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-14 Thread Graham Cox
On 15 Jul 2014, at 4:54 am, Jens Alfke j...@mooseyard.com wrote: The equivalent function in the ‘classic’ Mac OS had the very appropriate name of Munger( ) since it would munge bytes around in a heap block. Knowing how to use Munger was a sign of geek cred in the old (80s-90s) Mac dev

[NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Carl Hoefs
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

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Matt Gough
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 newsli...@autonomy.caltech.edu wrote: Basically what I would

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread Carl Hoefs
On Jul 12, 2014, at 1:51 PM, Matt Gough devlists...@gmail.com wrote: [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; Wow, I would never have thought to do that! Works perfectly! Thx, -Carl ___ Cocoa-dev mailing list

Re: [NSMutableData resetDataRangeTo:(NSRange)range];

2014-07-12 Thread SevenBits
On Saturday, July 12, 2014, Carl Hoefs newsli...@autonomy.caltech.edu wrote: On Jul 12, 2014, at 1:51 PM, Matt Gough devlists...@gmail.com javascript:; wrote: [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; Wow, I would never have thought to do that! Works