• 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: Automagic instantiation of singletons? (Christian Brunschen)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automagic instantiation of singletons? (Christian Brunschen)


  • Subject: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • From: Theo Vosse <email@hidden>
  • Date: Sun, 20 Nov 2005 13:07:13 +0100

That's a lousy way to do it in C++, because you have no portable and
reliable way to control the order of instantiation, so you have to make
*sure* that there is *no* dependency anywhere between any 2 singletons,

It is a simple way of making things like factory singletons. If you have more complex needs, you should write initialization code, of course.


It's even worse in Objective-C++, since the C++ statics may be constructed
before the Cocoa runtime is completely up, and may be destructed after it is
at least partially torn down.

The C++ standard is quite clear on what should happen (the constructors are called before main), and although I don't know of a guarantee that any interaction with NS classes will function at that point, it should if the descriptions of +(void)initialize are correct. However, I do consider it a bad idea to use C++ singletons to set up something in Cocoa.


	Theo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Automagic instantiation of singletons? (Christian Brunschen)
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: V.simple nstreecontroller example?
  • Next by Date: Re: Cocoa framework for iSight?
  • Previous by thread: Re: Cocoa framework for iSight?
  • Next by thread: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • Index(es):
    • Date
    • Thread