Re: NSData Questions
Re: NSData Questions
- Subject: Re: NSData Questions
- From: Alastair Houghton <email@hidden>
- Date: Mon, 10 Aug 2009 21:28:01 +0100
On 8 Aug 2009, at 22:45, Eric Hermanson wrote:
1. Is it more efficient to malloc a uint8_t array and call NSData
'init no copy', rather than pass in an array allocated with a fixed
length on the stack to the init method that makes a copy of the bytes?
2. Does NSMutableData's implementation simply just cast it's
internal bytes to const in the 'bytes' method, or does it internally
copy the bytes into a new autoreleased NSData and return the 'bytes'
for that copy, for example?
In general I don't think it's worth worrying too much about these
kinds of details, other than to say that Apple only employs decent
software engineers, so you won't find their code doing anything
particularly inefficient in general. Indeed, sometimes it turns out
to be more efficient than you might naïvely assume (for instance some
of the collection classes tune their implementations to the size of
data they're storing).
Anyway, if you're really interested, you can see the underlying
implementation in the Open Source part of CoreFoundation; the most
recent release on Apple's site is CF-476.18, and you can find it here:
<http://www.opensource.apple.com/release/mac-os-x-1057/>
Many of the toll-free bridged classes' implementations are (mostly)
exposed in that project. I say mostly because it's fairly clear that
the CF project is a subset of the *actual* CoreFoundation framework.
But it's useful to be able to see how things work sometimes.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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