Original Post
Recently, I've been working on yet another version of my basecode/game-engine code/etc. As far as singletons go, I've never really paid much attention to them, but I had stumbled across an article after browsing these forums a bit and I was intrigued. To get right to the point, I'm torn between sticking with my current method of implementing "singletons", which is essentially a class with all static data and all static functions, and actual singletons. I never instantiate the object and all calls to functions, accessors, etc, are things like Engine::loadThis() and Window::setThat(). After looking over a few simple true singleton implementations, I can't decide on whether the pros outweigh the cons or not. I see it as such: It's a little less typing using the global pointer, since I'm not constantly writing Engine:: or Window:: or FileSys::, but is there an advantage under the hood over what I'm doing currently? My initial thoughts make me feel like constantly accessing pointer to call functions (__thiscall) is extra machine code, but with compiler optimizing, this may not be an issue. Any thoughts on the good, the bad, and the ugly? What do you guys use? I'm stuck.
// static version example
int main()
{
Engine::init();
Engine::doStuff();
Engine::shutdown();
}
// or singleton, with a global pointer
Engine* e;
int main()
{
e = Engine::getInstance();
e->init();
e->doStuff();
e->shutdown();
}