March 19, 2013

Singleton design pattern C++ (bookmark)

I am still waiting for my GoF book to arrive, thus I have to read some articles.. This time I was curious about singleton design pattern, there's a user type object in my application which has to be only one. To implement simple singleton, I chose Scott Mayers Singleton (from Effective C++).

C++ Singleton Implementation [vladislavonline.com]
Here's comparison between GoF implementation and Scott Mayer's.

Several C++ singleton implementations [silviuardelean.ro]
4 approaches presented, but scott mayers is slighty different, because copy and assignment are defined, which is not the original version.

Anyway, the best reference is the book Modern C++ Design. Chapter 6 contains information about implementation of Singleton, how to handle destroying it and also multi threaded application concern.
In case you don't have a copy of the book, this presentation uses sources from it, check it out:
Singleton C++ [www10.informatik.uni-erlangen.de]