• 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: storage for context: value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: storage for context: value


  • Subject: Re: storage for context: value
  • From: Scott Ribe <email@hidden>
  • Date: Thu, 25 Jul 2013 08:33:50 -0600

On Jul 25, 2013, at 8:20 AM, Matt Neuburg <email@hidden> wrote:

> Is this the only safe/sensible storage? Could it be an actual object, cast back and forth between id and void*? Could it be stored as an ivar? Thx as always - m.

No, of course, and yes ;-)

Now the static idiom you mentioned is nice in that you don't have to worry about it going out of scope just because a function completes and the stack frame is destroyed, and because at least the variable itself does not get munged. But of course to be useful, MYCONTEXT might have to hold references to objects, and then you're back to having to manage the lifetimes of what is referred to. Also, it's only good when you only need 1 of the particular callback/info combinations to be active, and I find that's an unrealistic restriction, and is why I have (IIRC) never used this idiom. Note: I'm developing Mac software, so most of my windows/controllers can (and in normal use often will) have multiple instances existing at once. (In iOS I expect that it would be far more common to have window/controller pairs where there is never more than instance in simultaneous existence.)

I think the issue of *what* the context info refers to is far far less important than the issue of controlling the contexts (harhar) in which it is managed. If you're retaining/releasing them all throughout your code, you're asking for trouble. If you alloc an object per callback setup, right where you set up the callback, and release it in the callback, you're safe--and that's a very common pattern I think.

--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice





_______________________________________________

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


  • Follow-Ups:
    • Re: storage for context: value
      • From: Matt Neuburg <email@hidden>
References: 
 >storage for context: value (From: Matt Neuburg <email@hidden>)

  • Prev by Date: NSTask interrupt exception
  • Next by Date: Re: storage for context: value
  • Previous by thread: storage for context: value
  • Next by thread: Re: storage for context: value
  • Index(es):
    • Date
    • Thread