Re: dataWithBytesNoCopy:length:freeWhenDone
Re: dataWithBytesNoCopy:length:freeWhenDone
- Subject: Re: dataWithBytesNoCopy:length:freeWhenDone
- From: Quincey Morris <email@hidden>
- Date: Sat, 08 Oct 2011 20:05:57 -0700
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?
Presumably you're using 'dataWithBytesNoCopy:length:freeWhenDone:NO', since 'dataWithBytesNoCopy:length:freeWhenDone:YES' would be invalid in the scenario you describe.
I'd guess that, with the 'NO' parameter, NSMutableData copies the data anyway. Mutating the data would become treacherous if the underlying memory doesn't belong to the NSMutableData object that's trying to mutate it.
So, really all you could do is change individual bytes, and you scarcely need subsidiary NSMutableData objects for that -- simple C pointers would do. (Note, however, that you'd be using interior pointers, which would open you up to a range of possible memory management issues, depending on which memory model you're using.)
What are you trying to get the subsidiary NSMutableData objects to do for you that C pointers won't?
_______________________________________________
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