tags:

views:

448

answers:

2

I have a lllooonnnggg NSMutableData instance. I want to feed non-overlapping sub-ranges this data to other objects. I've perused the NSData/NSMutableData docs and don't quite have a grasp of the proper way to do this.

So for example the NSMutableData replaceBytesInRange:withBytes: looks ideal but I need the withBytes: parameter to point to a location beyond the head of the byte stream returned by [mySourceHumungousData bytes].

I can get hack-ish and drop into pure C and do this but I'd prefer not to do that.

Cheers, Doug

+3  A: 

Try subdataWithRange: on an NSData instance. That should let you slice up your data however you want it before you go to replace the desired bytes in your NSMutableData.

Gordon Worley
Thanks Gordon, that'll work. Cheers.
dugla
+1  A: 

As suggested you could use the subdataWithRange: message, or use getBytes:range: to copy into a buffer then pass the raw copied buffer. Either of these would achieve the same result. But to eliminate copying the data temporarily, you could just go 'C-style' and cast to a char *, increment [n] bytes to where you want and pass that.

Nick Bedford