Low-Lock Singletons In D
Steven Schveighoffer
schveiguy at yahoo.com
Mon May 6 14:54:10 PDT 2013
On Mon, 06 May 2013 17:36:00 -0400, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 5/6/13, Diggory <diggsey at googlemail.com> wrote:
>> Although that's only a single-per-thread-ton :P
>
> My bad.
>
>> final abstract class singleton
>> {
>> __gshared:
>> void foo() { }
>> int f;
>> }
The point that is missed is the lazy creation. Imagine if it's not just
an int but a whole large resource, which takes a long time to create/open.
If all we cared about is access, and you *know* you are going to need it,
you can just create it eagerly via shared static this(). That is not what
the singleton pattern is for.
-Steve
More information about the Digitalmars-d
mailing list