+1  A: 

Using case A has following benefits:

  1. You reduce dependency between classes SingletonClassMembers and SingletonHiddenImpl.
  2. You don't need to create configurator pattern in class SingletonClassMembers if you trying avoid restriction on (1) by dependency injection
  3. This case is weak, but anyway: it is simple to maintenance single class
  4. In multithreading environment you will need to support both class synchronization mechanism, while in single class only single locks is needed.
Dewfy
You have misunderstood me ;) There`s no dependency between SingletonClassMembers and SingletonHiddenImpl classes at all. They are provided to demonstrate differrent approaches to storing implementation data
konstantin
Nim
@konstantin - I get you point and my answer is correct, I'm sorry that used the same names for classes. My point was: in second case you need some solution to implement dependency injection between front-class and impl-class.
Dewfy
@Nim - very good comment, +1. I just need to make comment: @konstantin has asked: "what are the advantages of storing implementation data as class members (A)" - so I just figures this point. Another thing about multithreading. Singleton in multithread environment should be also safe (to avoid creating 2 instances from different threads simultaneously)
Dewfy
@Nim - it seems for me that almost everyone will agree that it is better to use forward declarations instead of gratuitous \#includes to reduce compile-time dependencies. I prefer (B) for the same reason
konstantin
@Dewfy Sorry, but you didn`t get my point. There`s no impl-class. 'Impl' is just a simple structure that is forward-declared in the header file and defined in implementation file. Therefore it is not possible to use it from the other place and your points don`t apply...
konstantin
+1  A: 

As you only have one instance of your singleton, you can actually move your helpers into the implementation class as "static" there without requiring them to be private inside the header. Of course you don't want to initialise them until you start your class so you would use some kind of smart-pointer, could be auto_ptr here or boost::scoped_ptr, or a pointer with boost::once initialisation (more thread-safe) with deletes in your singleton's destructor.

You can call this model C and probably has the best of both worlds as you completely hide your implementation.

As is the case with any singleton, you need to be extra careful not to throw in your constructor.

CashCow
It seems for me that (B) model is exactly the same. What is the difference ?
konstantin
+1  A: 

When considering efficiency with pimpl, it is not the heap that causes overhead, but the indirection (done by delegation). This delegation typically isn't optimized out (at least not at the time I was considering this ;-)), so there is not a big gain apart from the startup (1 time) penalty for creating the impl. (BTW, I didn't see any delegation functions in your example)

So I don't see that much difference in using pimpl in normal classes or in singletons. I think in both case, using pimpl for classes with limited interface and heavy implementation, it makes sense.

stefaanv
I agree that for this case, allocating 'Impl' on heap is not an issue. However, when objects are continuously created during runtime, this may become an issue too because calling a system call is a pretty expensive operation.
konstantin