开发者

NSData & NSMutabledata. How do I read from within the body of a data object?

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜