On Feb 27, 2017, at 11:11 , Jens Alfke <j...@mooseyard.com> wrote:
> 
>> On Feb 27, 2017, at 10:02 AM, Chris Ridd <chrisr...@mac.com 
>> <mailto:chrisr...@mac.com>> wrote:
>> 
>> It isn’t NSData, but libdispatch’s dispatch_data_t might be a useful way 
>> forward. The dispatch_data_create(3) man page says it avoids "copying the 
>> represented memory as much as possible.”
> 
> There’s some kind of bridging between the two — in the debugger I’ve seen 
> NSData objects (passed to my NSURLSession delegates) that have some internal 
> subclass name implying they’re bridged dispatch_data_t’s. (I don’t know if 
> this is toll-free or not, but it would be easy to do an experiment.)

First, if you read the man page more carefully, or if you look at the GCD 
dispatch_data_create API web page, you’ll see that the copying behavior of 
*this* function is deterministically a copy or not (unless you provide a custom 
destructor, where the memory management is done by the client, which isn’t what 
we’re talking about here). The statement appears to describe the functions on 
that man page *generally*.

Second, it’s not at all clear whether creating subdata without copying is 
regarded as “possible” or not, since none of the documentation seems to say. It 
sounds plausible, but who knows. <shrug>

Third, there are actually two things going on here. One is data objects that 
are built of of multiple discontiguous buffers (which dispatch_data_t objects 
always could be). The other is data objects that are subdata objects of another 
object.

The latter was always possible with NSData objects, though I think the actual 
“subdata” API is recent. (The documentation says macOS 10.12+, so pretty 
recent.) The former was originally possible only for dispatch_data_t objects, 
but there was a special NSData wrapper subclass that allowed them to be 
accessed via NSData APIs too. IIRC, dispatch_data_t objects are now an actual 
subclass of NSData, and the fragmented data format can be produced in other 
situations — with the restriction that such objects can only be created by 
explicit request, since much existing code would break if there wasn’t a single 
internal pointer to the entire data byte array.

My point is that Jens is here describing the fragmented form of NSData, which 
may be related to but isn’t the same as the subdata form of NSData.

And, of course, none of this answers the original question. I agree with Jens’s 
earlier answers: “Who knows? <shrug>”, and “Don’t rely on the current 
implementation."
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to