D
Dominik Rau
Hi.
I've got the following problem here: In my application, I use a lot of
Singletons, that are implemented as described in Gamma et al. (shortened):
//.h
class Singleton{
public:
static Singleton* the();
private:
static Singleton* _instance;
}
//.cpp
Singleton* the(){
if(!_instance)
_instance=new Singleton;
return _instance;
}
There's no problem in my core application, which is statically linked
with the singleton classes, e.g. if I use Singleton::the()->xyz() in
main(), the object is created, and a later call uses this object as
expected.
The problem arises, if I try to use these Singletons in plugins / parts
of the program that are loaded with - in my case - dlopen(). It is
impossible for me to access a Singleton object, that was already created
in the main application from a plugin. There are 2 Singletons
afterwards, one in the scope of the plugin and one in the scope of the
main application.
Example:
main(){
//first call, create Singleton by accessing it
Singleton::the()->xxx();
Plugin* p=loadPluginWithDlopen();
p->yyy(); //Call to a virtual method of class Plugin
}
//ConcretePlugin is derived of plugin, yyy declared virtual
void ConcretePlugin::yyy(){
//Should use the same Singleton as above, but creates a new one.
Singleton::the()->zzz();
}
The question: How can I access the Singleton used in the core
application with the plugin? I guess that there's an "extern" missing
somewhere, but I can't solve it. Any suggestions?!
In case that this is important: I'm working with gcc version 3.3.5 on
Debian/GNU Linux(testing).
Thanks & regards,
Dominik
I've got the following problem here: In my application, I use a lot of
Singletons, that are implemented as described in Gamma et al. (shortened):
//.h
class Singleton{
public:
static Singleton* the();
private:
static Singleton* _instance;
}
//.cpp
Singleton* the(){
if(!_instance)
_instance=new Singleton;
return _instance;
}
There's no problem in my core application, which is statically linked
with the singleton classes, e.g. if I use Singleton::the()->xyz() in
main(), the object is created, and a later call uses this object as
expected.
The problem arises, if I try to use these Singletons in plugins / parts
of the program that are loaded with - in my case - dlopen(). It is
impossible for me to access a Singleton object, that was already created
in the main application from a plugin. There are 2 Singletons
afterwards, one in the scope of the plugin and one in the scope of the
main application.
Example:
main(){
//first call, create Singleton by accessing it
Singleton::the()->xxx();
Plugin* p=loadPluginWithDlopen();
p->yyy(); //Call to a virtual method of class Plugin
}
//ConcretePlugin is derived of plugin, yyy declared virtual
void ConcretePlugin::yyy(){
//Should use the same Singleton as above, but creates a new one.
Singleton::the()->zzz();
}
The question: How can I access the Singleton used in the core
application with the plugin? I guess that there's an "extern" missing
somewhere, but I can't solve it. Any suggestions?!
In case that this is important: I'm working with gcc version 3.3.5 on
Debian/GNU Linux(testing).
Thanks & regards,
Dominik