On Jan 6, 2011, at 12:17 PM, Jonathon Kuo wrote:

> 
> On Jan 5, 2011, at 12:41 PM, Dave Keck wrote:
> 
>>> Q: When a context object is set with dispatch_set_context(), is it 
>>> retained? Or do I need to retain it first, set it, and then in the cancel 
>>> handler release it?
>> 
>> The 'context' argument is not retained. You can infer this primarily
>> by the declaration of dispatch_set_context(), and also the mention
>> that 'context' is "client defined" in dispatch/object.h; since the
>> 'context' argument is an untyped pointer (void *),
>> dispatch_set_context() cannot assume anything about the supplied
>> 'context' argument, much less that it's a valid libdispatch object.
>> 
> So I can supply anything here and GCD stores it _by value_, whether its a 
> simple integer or even a object pointer?

Yes, that is the nature of void *. Nothing can be known about a void * other 
than the value – therefore you can store anything there (even non-pointers as 
long as they are <= sizeof(void *)).

Note, the finalizer passed to dispatch_set_finalizer_f() will not be called if 
the value is zero.

davez_______________________________________________

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 arch...@mail-archive.com

Reply via email to