On Thursday, 5 January 2012 at 22:15:32 UTC, asm wrote:
how can i implementing the singleton pattern in D?
https://p0nce.github.io/d-idioms/#Leveraging-TLS-for-a-fast-thread-safe-singleton
On Saturday, 9 July 2016 at 20:47:32 UTC, Ali Çehreli wrote:
On 07/09/2016 01:35 PM, Suliman wrote:
> On Thursday, 5 January 2012 at 22:53:12 UTC, Ali Çehreli
wrote:
>> On 01/05/2012 02:15 PM, asm wrote:
>>> how can i implementing the singleton pattern in D?
>>
>
On 07/09/2016 01:35 PM, Suliman wrote:
> On Thursday, 5 January 2012 at 22:53:12 UTC, Ali Çehreli wrote:
>> On 01/05/2012 02:15 PM, asm wrote:
>>> how can i implementing the singleton pattern in D?
>>
>> Is singleton still alive? ;)
I'm glad I was alive in 2012
On Thursday, 5 January 2012 at 22:53:12 UTC, Ali Çehreli wrote:
On 01/05/2012 02:15 PM, asm wrote:
how can i implementing the singleton pattern in D?
Is singleton still alive? ;)
An idea is to instantiate the object in the module's static
this().
Ali
Yeah, same question, what diffe
On Thursday, 24 January 2013 at 16:49:53 UTC, Maxim Fomin wrote:
On Thursday, 24 January 2013 at 16:17:34 UTC, Era Scarecrow
wrote:
Hmmm. You could separate the data and remove the pointer...
then use alias this.
[code]
struct Singleton {
static SingletonData single;
alias single this;
On Thursday, 24 January 2013 at 17:35:58 UTC, Ali Çehreli wrote:
On 01/24/2013 09:26 AM, ParticlePeter wrote:
> Thanks, I re-read the purpose of ref type function() in the D
> programming language, and the sole purpose is that such a
function call
> can be directly a parameter to another functio
On 01/24/13 18:35, ParticlePeter wrote:
> On Thursday, 24 January 2013 at 17:21:38 UTC, Artur Skawina wrote:
>> On 01/24/13 17:52, ParticlePeter wrote:
>>> Why is the s inside the struct and another_s not identical ?
>>> Afaik that is the purpose of the ref keyword ?
>>
>> There currently are no re
On 01/24/2013 09:26 AM, ParticlePeter wrote:
> Thanks, I re-read the purpose of ref type function() in the D
> programming language, and the sole purpose is that such a function call
> can be directly a parameter to another function expecting a ref ?
As Maxim Fomin noted, I didn't word it correc
On Thursday, 24 January 2013 at 17:21:38 UTC, Artur Skawina wrote:
On 01/24/13 17:52, ParticlePeter wrote:
Yes, but this can be broken by:
import core.stdc.stdio : printf;
struct Singleton {
private :
this( int a = 0 ) {} ;
static Singleton * s ;
public :
@disable th
On Thursday, 24 January 2013 at 17:00:44 UTC, Ali Çehreli wrote:
On 01/24/2013 08:52 AM, ParticlePeter wrote:
> This method here ( my first approach ) does return a
reference to an
> object on the heap, right ?
Yes, but the caller does not get a reference.
> static ref Singleton instance() {
>
On 01/24/13 18:14, Artur Skawina wrote:
> struct Singleton {
> private:
> this( int a = 0 ) {} ;
> static Singleton* s ;
>
> public:
> @disable this();
> @disable this(this);
> static instance() @property {
> static struct Ref(T) { T* obj; ref g() @property { return *o
On 01/24/13 17:52, ParticlePeter wrote:
>> Yes, but this can be broken by:
>>
>> import core.stdc.stdio : printf;
>>
>> struct Singleton {
>>
>> private :
>> this( int a = 0 ) {} ;
>> static Singleton * s ;
>>
>> public :
>> @disable this() ;
>> static Singleton* in
On Thursday, 24 January 2013 at 17:00:44 UTC, Ali Çehreli wrote:
On 01/24/2013 08:52 AM, ParticlePeter wrote:
> This method here ( my first approach ) does return a
reference to an
> object on the heap, right ?
Yes, but the caller does not get a reference.
Actually the caller gets the referen
On 01/24/2013 08:52 AM, ParticlePeter wrote:
> This method here ( my first approach ) does return a reference to an
> object on the heap, right ?
Yes, but the caller does not get a reference.
> static ref Singleton instance() {
> if ( s is null )
> s = new Singleton( 0 ) ;
> return * s ;
> }
>
Yes, but this can be broken by:
import core.stdc.stdio : printf;
struct Singleton {
private :
this( int a = 0 ) {} ;
static Singleton * s ;
public :
@disable this() ;
static Singleton* instance() {
if ( s is null )
s = n
On Thursday, 24 January 2013 at 16:17:34 UTC, Era Scarecrow wrote:
On Thursday, 24 January 2013 at 16:07:36 UTC, Maxim Fomin wrote:
Yes, but this can be broken by:
void main()
{
Singleton s = * Singleton.instance;
printf( "%d\n", s.val ) ; //
Singleton.instance.val = 2 ;
On Thursday, 24 January 2013 at 16:07:36 UTC, Maxim Fomin wrote:
Yes, but this can be broken by:
void main()
{
Singleton s = * Singleton.instance;
printf( "%d\n", s.val ) ; //
Singleton.instance.val = 2 ;
printf( "%d\n", s.val ) ; //0
}
Here s is explicitly def
On Thursday, 24 January 2013 at 15:50:34 UTC, ParticlePeter wrote:
Got it, thanks, I changed the instance method to:
[code]
static Singleton * instance() {
if ( s is null )
s = new Singleton( 0 ) ;
return s ;
}
[\code]
and
Got it, thanks, I changed the instance method to:
[code]
static Singleton * instance() {
if ( s is null )
s = new Singleton( 0 ) ;
return s ;
}
[\code]
and everything works as expected.
Cheers, PP !
On Thursday, 24 January 2013 at 15:05:15 UTC, Jacob Carlborg
wrote:
On 2013-01-24 15:43, Maxim Fomin wrote:
Even if Singleton.instance returns by ref, s object is still
stack-allocated struct, which is not affected by further
modification of
private pointer.
The struct is allocated using "n
Even if Singleton.instance returns by ref, s object is still
stack-allocated struct, which is not affected by further
modification of private pointer.
But where and when is ( a second ? ) Singleton created or
duplicated ? The only ctor is in the static instance ( it is
called only once accor
On 2013-01-24 15:43, Maxim Fomin wrote:
Even if Singleton.instance returns by ref, s object is still
stack-allocated struct, which is not affected by further modification of
private pointer.
The struct is allocated using "new".
--
/Jacob Carlborg
On Thursday, 24 January 2013 at 14:11:10 UTC, ParticlePeter wrote:
Hi,
I am trying to figure out the singleton pattern with a struct
instead of a class:
[code]
struct Singleton {
private :
this( int a = 0 ) {} ;
static Singleton * s ;
public :
@disable this
Hi,
I am trying to figure out the singleton pattern with a struct
instead of a class:
[code]
struct Singleton {
private :
this( int a = 0 ) {} ;
static Singleton * s ;
public :
@disable this() ;
static ref Singleton instance() {
if ( s is
On Thursday, January 12, 2012 00:55:14 Thomas Mader wrote:
> On Friday, January 6, 2012, Jonathan M Davis wrote:
> > The same way that you would in C++ or Java, except that unlike you have
>
> static
>
> The most simple and elegant way in java is to use an enum. Is there nothing
> comparable in
On Friday, January 6, 2012, Jonathan M Davis wrote:
> The same way that you would in C++ or Java, except that unlike you have
static
The most simple and elegant way in java is to use an enum. Is there nothing
comparable in D?
thank you, you answer is very helpful.
On Thursday, January 05, 2012 22:15:32 asm wrote:
> how can i implementing the singleton pattern in D?
The same way that you would in C++ or Java, except that unlike you have static
constructors that you can use to initialize them, and unlike both, if it's not
shared, then it's a
On 01/05/2012 02:15 PM, asm wrote:
how can i implementing the singleton pattern in D?
Is singleton still alive? ;)
An idea is to instantiate the object in the module's static this().
Ali
both if you don't mind
On Thu, Jan 5, 2012 at 4:15 PM, asm wrote:
> how can i implementing the singleton pattern in D?
Multithreaded or not?
how can i implementing the singleton pattern in D?
32 matches
Mail list logo