[Boost-users] [pool] Singleton implementation

34 views
Skip to first unread message

Paul Byrne

unread,
Oct 19, 2009, 8:14:15 PM10/19/09
to boost...@lists.boost.org
Hi all,

I am interested to find a sound C++ implementation of a Singleton, and have attempted to find one within the Boost libraries. It seems that "pool/detail/singleton.hpp" would fit the bill for me, but (as I understand it) this class/header is not intended for direct use by library users. Have I overlooked a good alternative within the Boost suite?

Thanks, Paul
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Ray Burkholder

unread,
Oct 20, 2009, 7:59:23 AM10/20/09
to boost...@lists.boost.org
>
> I am interested to find a sound C++ implementation of a Singleton, and
> have attempted to find one within the Boost libraries. It seems that
> "pool/detail/singleton.hpp" would fit the bill for me, but (as I
> understand it) this class/header is not intended for direct use by
> library users. Have I overlooked a good alternative within the Boost
> suite?
>

I don't think there is something in boost. Here is some research I did on
Singletons:
http://www.oneunified.net/blog/Personal/SoftwareDevelopment/CPP/Singleton.ar
ticle
http://www.oneunified.net/blog/Personal/SoftwareDevelopment/CPP/SingletonPer
Thread.article

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

J.W.F. Thirion

unread,
Oct 20, 2009, 8:11:00 AM10/20/09
to boost...@lists.boost.org
You could try:
http://www.boostcookbook.com/Recipe:/1235044

Kind regards,
Derik

On Tue, 2009-10-20 at 08:59 -0300, Ray Burkholder wrote:
> >
> > I am interested to find a sound C++ implementation of a Singleton, and
> > have attempted to find one within the Boost libraries. It seems that
> > "pool/detail/singleton.hpp" would fit the bill for me, but (as I
> > understand it) this class/header is not intended for direct use by
> > library users. Have I overlooked a good alternative within the Boost
> > suite?
> >
>
> I don't think there is something in boost. Here is some research I did on
> Singletons:
> http://www.oneunified.net/blog/Personal/SoftwareDevelopment/CPP/Singleton.ar
> ticle
> http://www.oneunified.net/blog/Personal/SoftwareDevelopment/CPP/SingletonPer
> Thread.article
>
>
>

_______________________________________________

Larry

unread,
Oct 20, 2009, 8:28:01 AM10/20/09
to boost...@lists.boost.org
FWIW. I occasionally use a scheme in the Loki library. For my needs it was
simple and worked.
I have not run into any coexistence problems with Boost (1.32 through 1.40
on Windows with
MSVC 6, 7, 8, or 9).

Larry

Eric J. Holtman

unread,
Oct 20, 2009, 8:46:41 AM10/20/09
to boost...@lists.boost.org
Larry wrote:
> FWIW. I occasionally use a scheme in the Loki library. For my needs it
> was simple and worked.
> I have not run into any coexistence problems with Boost (1.32 through
> 1.40 on Windows with
> MSVC 6, 7, 8, or 9).
>

I have used Loki stuff too. Under windows, if you're using DLLs though,
you will need some magic incantations to keep from having multiple
copies of the Singleton appear.

Basically, you need to ensure the templates (which contain static data)
get instantiated only once.

Robert Ramey

unread,
Oct 20, 2009, 10:43:40 AM10/20/09
to boost...@lists.boost.org
You might want to look at the singleton which is part of the serialization
library.

Robert Ramey

Robert Ramey

unread,
Oct 20, 2009, 10:46:35 AM10/20/09
to boost...@lists.boost.org
Eric J. Holtman wrote:
> Larry wrote:
>> FWIW. I occasionally use a scheme in the Loki library. For my needs
>> it was simple and worked.
>> I have not run into any coexistence problems with Boost (1.32 through
>> 1.40 on Windows with
>> MSVC 6, 7, 8, or 9).
>>
>
> I have used Loki stuff too. Under windows, if you're using DLLs
> though, you will need some magic incantations to keep from having
> multiple copies of the Singleton appear.

This is not unique to windows - same issue with linux and I presume
others.

>
> Basically, you need to ensure the templates (which contain static
> data) get instantiated only once.

how do you do this?

Robert Ramey

Eric J. Holtman

unread,
Oct 20, 2009, 9:52:45 AM10/20/09
to boost...@lists.boost.org
Robert Ramey wrote:
>
>> Basically, you need to ensure the templates (which contain static
>> data) get instantiated only once.
>>
>
> how do you do this?
>
>

This is not a Loki mailing list, so I don't want to chew up
tons of bandwidth, but you can look at SingletonDLL
under their distribution for hints.

I've found that there's still some wonky-ness with
Microsoft's compiler, and so I pretty much gave up
on trying to globally fix the issues, and ending up
having actual concrete classes for my factories,
which inside their .cpp implemetation files used
the templated Singletons in an anonymous namespace.

That way, the templates only ever appear in implemetation
files, but not in headers, so I only get one copy.

Maybe someday I'll go back and re-visit the issue,
but the last time I looked into it, I was more interested
in "a solution for Eric's programs" than the "100% correct
solution for everyone's programs".

Paul Byrne

unread,
Oct 20, 2009, 10:57:32 PM10/20/09
to boost...@lists.boost.org

>
> Message: 8
> Date: Tue, 20 Oct 2009 06:43:40 -0800
> From: "Robert Ramey" <ra...@rrsd.com>
> To: boost...@lists.boost.org

> Subject: Re: [Boost-users] [pool] Singleton implementation
> Message-ID: <hbkeik$jah$1...@ger.gmane.org>

>
> You might want to look at the singleton which is part of the serialization
> library.
>
> Robert Ramey
>

Thanks Robert, Ray et al for the useful pointers.

Reply all
Reply to author
Forward
0 new messages