• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dataWithBytesNoCopy:length:freeWhenDone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dataWithBytesNoCopy:length:freeWhenDone


  • Subject: Re: dataWithBytesNoCopy:length:freeWhenDone
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 08 Oct 2011 22:50:32 -0500

On Oct 8, 2011, at 10:05 PM, Quincey Morris wrote:

> On Oct 8, 2011, at 14:31 , email@hidden wrote:
>
>> What am I doing wrong? Shouldn't the instance created using
>> dataWithBytesNoCopy:length:freeWhenDone simply hold the same bytes as
>> the originally provided ones?

> I'd guess that, with the 'NO' parameter, NSMutableData copies the data anyway.

This is actually documented.  In the Binary Data Programming Guide, in the article Working With Binary Data[1], it says:

> However, if you create an NSData object with one of the methods whose name includes NoCopy (such as dataWithBytesNoCopy:length:), the bytes are not copied. Instead, the data object takes ownership of the bytes passed in as an argument and frees them when the object is released. (NSMutableData responds to these methods, too, but the bytes are copied anyway and the buffer is freed immediately.)

Cheers,
Ken

[1] https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/BinaryData/Tasks/WorkingBinaryData.html

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: dataWithBytesNoCopy:length:freeWhenDone
      • From: email@hidden
References: 
 >dataWithBytesNoCopy:length:freeWhenDone (From: email@hidden)
 >Re: dataWithBytesNoCopy:length:freeWhenDone (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: return NO in tableViewSelectionDidChange: disables button cell
  • Next by Date: -dateWithTimeIntervalSinceNow: 64-bits may overflow
  • Previous by thread: Re: dataWithBytesNoCopy:length:freeWhenDone
  • Next by thread: Re: dataWithBytesNoCopy:length:freeWhenDone
  • Index(es):
    • Date
    • Thread