Re: Encoding function pointer in an NSValue
Re: Encoding function pointer in an NSValue
- Subject: Re: Encoding function pointer in an NSValue
- From: "Joshua Pennington" <email@hidden>
- Date: Thu, 24 May 2007 17:50:49 -0500
Cocoa-wizards, correct me if I'm wrong but,
Using valueWithPointer:foo, the NSValue is taking the address that foo
is pointing to (the function's location in memory). It will be
unaffected by the deallocation of pointer foo since the function is
not going to change locations in memory.
MyObjectComparitor foo = myFunction; // Assigns address to foo
NSValue *value = [NSValue valueWithPointer:foo]; // value now wraps
the address pointed to by foo. It isn't concerned with the variable
foo at all - it just wanted its value.
// ...... (foo goes out of scope)
MyObjectComparitor aFunctionPointer = [value pointerValue]; //
aFunctionPointer is now pointing to the address assigned to value from
foo (of course you should check for NULL before calling)
aFunctionPointer(objectA, objectB);
On 5/24/07, Ken Tozier <email@hidden> wrote:
The next question would be: What happens to the function pointer when
the wrapping value is deallocated? Wouldn't want it to invalidate the
function pointer.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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