where to store "global data to several DLL" ? - how manage a"shared-instance_ptr"?

Discussion in 'C++' started by nguillot, Apr 11, 2008.

  1. nguillot

    nguillot Guest


    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:

    template<class objectType>
    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!!
    nguillot, Apr 11, 2008
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laser Lu

    Garbage Collection and Manage Code?

    Laser Lu, Jan 26, 2004, in forum: ASP .Net
    Gaurav Khanna [C# MVP]
    Jan 27, 2004
  2. Berry Morgan
    Wayne Wengert
    May 17, 2004
  3. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Mar 30, 2005
  4. Steve
    Nov 4, 2005
  5. Johanna Espinosa

    Manage and Store Keys

    Johanna Espinosa, Jun 21, 2004, in forum: ASP .Net Security
    Hernan de Lahitte
    Jun 23, 2004

Share This Page