• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Encoding function pointer in an NSValue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Encoding function pointer in an NSValue (From: Ken Tozier <email@hidden>)
 >Re: Encoding function pointer in an NSValue (From: "Joshua Pennington" <email@hidden>)
 >Re: Encoding function pointer in an NSValue (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: [maybe slightly OT] iTunes and iPhoto plugin development
  • Next by Date: Simple hide window for x number of seconds...
  • Previous by thread: Re: Encoding function pointer in an NSValue
  • Next by thread: Re: Encoding function pointer in an NSValue
  • Index(es):
    • Date
    • Thread