[Singleton] pre-review question
Hello, I am currently evaluating boost.singleton for our application. I hope it is not too late to write a review. As I understood from the docs, Singleton instance is immediately (when all global and static variables are initilized) created. In our context we need singleton to be created on first request (as it is described in GoF). The problem is following: Our application must parse config file which is accessible after entering main and store the options/parameters parsed in a singleton class. If I initialize singleton immediately (before entering main) I can not parse command line options and have to trick around with some additional functions which do it for me (but a constructor would be a much better choice, when I try for the first time to access the singleton). Is that possible with the current implementation? I know I could overload operator-> and check that options are parsed, but I think this is a not so obvious scenario for everyone. With Kind Regards, Ovanes
Trying to compile the code (VC++ 7.1, boost 1.34.1) I faced the problem that
some header files are missing.
boost/utility/singleton.hpp includes:
# include
Hello,
I am currently evaluating boost.singleton for our application. I hope it is not too late to write a review. As I understood from the docs, Singleton instance is immediately (when all global and static variables are initilized) created. In our context we need singleton to be created on first request (as it is described in GoF).
The problem is following: Our application must parse config file which is accessible after entering main and store the options/parameters parsed in a singleton class. If I initialize singleton immediately (before entering main) I can not parse command line options and have to trick around with some additional functions which do it for me (but a constructor would be a much better choice, when I try for the first time to access the singleton).
Is that possible with the current implementation? I know I could overload operator-> and check that options are parsed, but I think this is a not so obvious scenario for everyone.
With Kind Regards, Ovanes
Ovanes Markarian wrote:
Trying to compile the code (VC++ 7.1, boost 1.34.1) I faced the problem that some header files are missing.
boost/utility/singleton.hpp includes:
# include
member_dereference.hpp includes: # include
# include # include # include I neather have function_types directory in singleton.zip nor in boost 1.34.1 distribution. Would be nice if someone could specify if some other additional libs are needed.
No additional libs are needed, just the svn version of Boost :-). A backport to 1.34 can be downloaded from the vault: http://tinyurl.com/2nelk4 Regards, Tobias
Ovanes Markarian wrote:
Hello,
I am currently evaluating boost.singleton for our application. I hope it is not too late to write a review. As I understood from the docs, Singleton instance is immediately (when all global and static variables are initilized) created. In our context we need singleton to be created on first request (as it is described in GoF).
Singleton is created on demand.
The problem is following: Our application must parse config file which is accessible after entering main and store the options/parameters parsed in a singleton class. If I initialize singleton immediately (before entering main) I can not parse command line options and have to trick around with some additional functions which do it for me (but a constructor would be a much better choice, when I try for the first time to access the singleton).
Is that possible with the current implementation?
I think so. Regards, Tobias
Many thanks that works fine! The singleton is really created on request.
I have one additional question about destruction of singletons. This simple
example was compiled with VC++ 7.1
#include
Ovanes Markarian wrote:
Hello,
I am currently evaluating boost.singleton for our application. I hope it is not too late to write a review. As I understood from the docs, Singleton instance is immediately (when all global and static variables are initilized) created. In our context we need singleton to be created on first request (as it is described in GoF).
Singleton is created on demand.
Ovanes Markarian wrote:
Many thanks that works fine! The singleton is really created on request.
<code>
This successfully creates a singleton but never calls the dtor of it.
It should work automatically. I have to look into it.
Should I always call explicitly destroy_singletons function?
Only if this function is exposed by (something that might be) a DLL and you are targeting platforms that need it. Regards, Tobias
participants (2)
-
Ovanes Markarian
-
Tobias Schwinger