TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: Serge Baltic
date: 2004-12-05 20:43:32
subject: Creating a singleton

((( Presented in DOLBY Surround )))
                            (where available)
Hi Neil, hope you are having a nice day

13 Nov 04, Neil Heller wrote to Serge Baltic:

 SB>> What do the constructors do to running multiple instances of your
 SB>> application?
 NH> If a constructor is private, it cannot be constructed by any process
 NH> other than itself.

What the hell about other processes? If a constructor is private, the
object cannot be created directly by either process. What is a "self
process"? Each process is self for some classes :)

It can be created in some function of this class. A static one, for obvious reasons.

 NH> In the public GetInstance() method,

"static" in the first place.

 NH> the reference can get checked for zero (having been declared static,
 NH> it will be initialized to zero when created) and if zero, the class
 NH> is created on the heap.

This does not prevent me from creating two instances of this object in
different processes. Moreover, I can even create two instances in a single
process if I load them from different modules --- because each module will
have a personal set of static variables and your singleton model will be
local to the module.

A static var is not enough. It would rather be some system synchronization
object, like a semaphore (within the process) or a mutex (interprocess as
well). Under Win* COM the model could be used to handle the singleton
problem.


 -=> Yours sincerely, Serge <=-

BTW, The world's oldest piece of chewing gum is over 9000 years old.

[SPb-SU-ITMO.ITP.CTD] [SPb-FML239.4.00] _/[HyPeR SoftWare]/_

... If you can't make it good, make it LOOK good. (c) Bill Gates
--- GoldED/386 3.0.1-asa9 SR1 Damned
* Origin: Silence Must Be Heard (2:5030/744.235)
SEEN-BY: 633/267 270
@PATH: 5030/744 966 5080/68 5 3830/9 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.