Re: ATL Singletons or Running Object Table ?
May I also suggest:
c) Register A in the ROT and have it return an interface to B
Some experts (Brian included) strongly advise against using
COM singletons. I admit it's a bit of a hack, though I don't have
such strong sentiments myself. In your case you don't really
need it since all you are sharing is a single interface pointer to
the object in your DLL. Thus:
d) Use a regular object A and share the instance of a pointer to
B among all instances of A. All instances of A return the same
interface pointer to the shared instance of B.
Based upon your description, there's no evidence to tip the
scales one way or another.
A further tip on exposing your object (something I presumed all
along) is that you need a forwarding object to stabilize your
executable lifetime (in case a client releases its pointer to A way
before it is finished using B - this should be the standard behavior
I'd assume) e.g. your module refcount in ATL speak. The perfect
solution is using Keith Brown's Universal Delegator. Unfortunately,
a quick search only turned up dead links (Keith used to work for
DevelopMentor and his UD was posted there, but not anymore).
You'll have to invest more time in order to find a good link. If you
can't find the UD, you can write a simple delegating object by hand...
You'll need the forwarding object no matter what approach you
choose.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Ignacio Burgue?o" <blabla@blabla.com> wrote in message
news:OvZ1x%2378GHA.4964@TK2MSFTNGP02.phx.gbl...
Hi everyone.
I have a question regarding whether I should use a singleton or the
Running Object Table.
I have a component (EXE) (let's call it ComponentA) which creates another
component (DLL) (ComponentB).
Other applications need to access ComponentB, and they all should share
its single instance.
So, I may:
a) Make ComponentA a singleton and add a method to it to return an
interface to ComponentB? Then the other application will retrieve
ComponentB going through ComponentA.
or
b) Make ComponentA place a reference to ComponentB in the ROT. Then other
applications will retrieve ComponentB from the ROT.
I've tested both scenarios and both works fine for me, but since I read
here that the use of DECLARE_CLASSFACTORY_SINGLETON has problems of its
own, I'd like to know your oppinion on the matter.
- What are the issues associated with using a singleton?
- What could be the implications of using the ROT?
In either case, I'm not worried about threading or concurrency issues on
ComponentB.
Thanks in advance,
Ignacio Burgue?o