Ah - it doesn't. We don't use a full-on singleton pattern - the singleton pattern is used only so that a variable can be accessed statically from anywhere. The accessor tends to look something like:Solar wrote:It does? I mean, instance() contains at least a check whether the singleton has been initialized. If you want to be thread-safe, that check would have to be mutexed. I don't say it's impossible to optimize that away, but...JamesM wrote:compiles down to the equivalent of:Code: Select all
MyClass::instance().doStuff();
With -O3.Code: Select all
MyClass myClass; myClass.doStuff();
Ah well.
Code: Select all
static const MyClass &instance()
{
return m_Instance;
}
James