On Sat, Jun 7, 2008 at 9:59 AM, Ricky Sharp <[EMAIL PROTECTED]> wrote:
> I will hope though that within the context of say memcpy, that the GC thread
> could not collect data.  For example, the following should be safe:
>
> memcpy(myLocalGCAwareBuffer, [data bytes], numberOfBytes);

Not at all. The semantics of this is identical to the semantics of
just writing your own loop. Nothing guarantees that the data pointer
stays on the stack during the memcpy. If nothing else references the
data then you *must* either ensure that a reference stays on the stack
(by, for example, messaging it afterwards) or you must disable
collection for it until you're done with its contents.

> Finally, I think that usages of NSMutableData may also be a bit tricky.  In
> my case I'll probably just obtain a copy of its bytes, manipulate them and
> then copy the result back in. Sort of ironic though in that the inner
> pointer would have been valid anyhow in such blocks of code (the
> NSMutableData instance would be around between the get and subsequent set of
> its bytes):
>
> NSMutableData* data = [...];
> const unsigned char* bytes = [data bytes];
> operate on copy of bytes in GC-aware buffer
> [data replaceBytesInRange:...];

This is unnecessary, since data is guaranteed to stay live throughout
your operation because you use it at the end. You only need to take
measures when your last reference to the NSData object comes before
your last reference to its bytes pointer.

Mike
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to