[gameprogrammer] Re: problem with singleton
- From: "Roger D. Vargas" <roger@xxxxxxxxxxx>
- To: Game programmer list <gameprogrammer@xxxxxxxxxxxxx>
- Date: Wed, 16 Jun 2004 08:57:01 -0400
El mié, 16-06-2004 a las 00:16, Dave Slutzkin escribió:
> Although... There is a slight problem with implementing Singleton this
> way, which you may or may not run into. (If you don't, don't worry
> about it.) This static object has to be initialized at some point, and
> the compiler will generate the code to initialize it at a random time
> (or at least, one which you have no control over). If you try to access
> it before it's initialized (like from the constructor of another static
> object), you run into problems because it's not created yet. So there
> are multiple other and probably better ways to do it, as mentioned in
> detail in Alexandrescu's Modern C++ Design book. This is a big, complex
> book though.
>
> Briefly, the other way I usually do it is:
>
> static TVTextures::singleton()
> {
> static TVTextures sSingleton;
> return sSingleton;
> }
>
> This ensures that as soon as the function is called, this object is
> allocated so it always exists when it's used.
>
What would be the best way to implement it but using a pointer for the
instance?
--
Roger D. Vargas
Linux User: 180787
ICQ: 117641572
jabber.ehtsc.co.cu: roger
"Object-oriented programming is an exceptionally bad idea which could
only have originated in California."
- E.W. Dijkstra
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: problem with singleton
- From: Dave Slutzkin
- References:
- [gameprogrammer] problem with singleton
- From: Roger D. Vargas
- [gameprogrammer] Re: problem with singleton
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] problem with singleton
- » [gameprogrammer] Re: problem with singleton
- » [gameprogrammer] Re: problem with singleton
- » [gameprogrammer] Re: problem with singleton
- » [gameprogrammer] Re: problem with singleton
- [gameprogrammer] Re: problem with singleton
- From: Dave Slutzkin
- [gameprogrammer] problem with singleton
- From: Roger D. Vargas
- [gameprogrammer] Re: problem with singleton
- From: Dave Slutzkin