> On Jun 8, 2015, at 11:47 PM, Roland King <[email protected]> wrote:
> 
> Without answering 98.7% of your question, or more. Are you wedded to NSData 
> for this? I have a stream processor, it takes randomly chunked up data from a 
> bluetooth dongle and .. processes it. I used dispatch_data_t for it. That was 
> introduced back with GCD a few years ago. It’s proved very good for this kind 
> of data manipulation. You can append them to each other, split them into 
> pieces, iterate over them but under the hood all the while it keeps the 
> original chunks of data and avoids a lot of copying around. Only if you at 
> some point want N contiguous bytes out of the thing to process as a byte 
> array will it do a copy if necessary into one single memory chunk, if the 
> piece you want is already in one chunk, it just returns it to you. I’ve found 
> it a good way to deal with buffers of bytes very efficiently and quite 
> intuitively. 

Note that a dispatch_data_t can be used as an NSData object (but not vice 
versa) as of iOS 7 and OS X 10.9. That means you can use dispatch_data_t to 
collect chunks as they arrive, then pass the result to a consumer that wants 
NSData. If all goes well you'll get NSData compatibility with zero or one extra 
copies.


-- 
Greg Parker     [email protected]     Runtime Wrangler



_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to