Click to See Complete Forum and Search --> : Singleton


muscicapa
June 16th, 1999, 07:48 AM
What is a singleton ?

Some time earlier I needed to get different clients to get the same object in later CoCreateInstance()s.
The solution in ATL was to use the macro DECLARE_CLASSFACTORY_SINGLETON(myClass)

This works as expected for Out-of-proc servers.

All was fine until, i tried out the same in an in-proc (dll )server. This obviously I thought may not give the same object in two different client processes, since the DLLs mapped in their processes dont by default share data. Then I got the real import of this when I made a single client which spawns of two threads, in each thread I coinitialize, cocreateinstance and call a method on the server. They do not get the same object, in order to see that they get the same object, i declared the class as a singleton and also postponed the call of release() to the end.

So what is a singleton, is it within the system, process or thread.

Also what does the ROTviewer show,
I thought the running objects would be shown and give me some insight on this situation. It didnt.