On 27. nóv. 2017, at 10:51 e.h., Quincey Morris 
<quinceymor...@rivergatesoftware.com> wrote:
> On Nov 27, 2017, at 22:36 , Daryle Walker <dary...@mac.com> wrote:
>> 
>> Is there a way to make a (NS)Data that uses multiple contiguous blocks?
> 
> You mean multiple *non-contiguous* blocks??
> 
> The only way I know of forcing Data to use multiple blocks is via 
> DispatchData.
> 
> (In recent OS versions, Data and DispatchData are sort of the same thing, but 
> I don’t remember where this is described.)

From an ObjC perspective, dispatch_data_t is one of the concrete subclasses of 
NSData. Swift doesn't know this, though, so you have to jump through some hoops.

The only documentation of this is in the 10.9 release notes (seriously, when 
did Apple's main documentation become so terrible?):

> dispatch_data_t -> NSData bridging
> 
> In 64-bit apps using either manual retain/release or ARC, dispatch_data_t can 
> now be freely cast to NSData *, though not vice versa. Note that one 
> implication of this is that NSData objects created by Cocoa may now contain 
> several discontiguous pieces of data. You can efficiently work with 
> discontiguous ranges of data by using the new
> 
>  - (void) enumerateByteRangesUsingBlock:(void (^)(const void *bytes, NSRange 
> byteRange, BOOL *stop))block
> API on NSData. This will be roughly the same speed as -bytes on a contiguous 
> NSData, but avoid allocation and copying for a discontiguous one. Once a 
> discontiguous NSData is compacted to a contiguous one (generally by calling 
> -bytes, other NSData API will do discontiguous accesses), future accesses to 
> the contiguous region will not require additional copying.
> 
> Various system APIs (in particular NSFileHandle) have been updated to use 
> discontiguous data for improved performance, so it's best to structure your 
> code to handle it unless it absolutely needs contiguous bytes. 
> 



_______________________________________________

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