where to store "global data to several DLL" ? - how manage a"shared-instance_ptr"?
I'm developing a framework built dynamically from a config file.
A builder reads a config file to know which DLLs to load to
instantiate some objects.
I've got one kind of object per DLL.
An objects is instantiated (new) by an entry point of the DLL
containing its declaration.
In fact the objects may be shared. So the entry point of the DLL is
something like that:
objectType* GetInstance(int instanceNb);
if the instanceNb has never been instantiated, the object is created
(new) and a map (static in the object's DLL) maps the instance number
to the adress of the object.
And when GetInstance is called with instanceNb of an already created
object, it just returns the address of this object and it increments a
reference count (stored also in the static map).
In fact I didn't know about boost::shared_ptr to count the references
on an object, so I counted the reference in this map. I maybe will use
But, my question:
The builder must store a set of all objects instantiated.
So The builder class could have a member set<void*> m_objects, and
each time we call GetInstance, we store the instance returned.
But it would be better, in order not to forget to do that, that
GetInstance populates itself the map. But is it possible? I mean: the
set should be part of the builder, because it's its stuff.
The builder is also on a separate DLL. So where to store the set? I
feel it's not correct to pass the set& to GetInstance...
I feel it's not correct to store the set as a singleton, or a variable
in a namespace.
And we must not forget to remove an entry of the set when the
reference count of an object reaches 0: because the object is
I'm starting to think about a shared_ptr specialised to do the job
each DLL does (if the instance doesn't exist: create one, if it does
exist, return it and increment the count).
Can I inherit from a shared_ptr? I read a briefly the code of a
shared_ptr but it's far to be easy ;-)
If you read until here, thank you!!
|All times are GMT. The time now is 01:03 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.