Re: SmartRef: The Smart Pointer In D

2018-06-08 Thread Martin Nowak via Digitalmars-d-announce

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I will write more test before the frist release.
And the docs is null.
It on github: https://github.com/huntlabs/SmartRef


I hope you know https://code.dlang.org/packages/automem.


Re: SmartRef: The Smart Pointer In D

2018-05-29 Thread Aedt via Digitalmars-d-announce

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.
it just Like cpp's shared_ptr , waek_ptr and unique_ptr .
Now, it is  Developing.
I will write more test before the frist release.
And the docs is null.
It on github: https://github.com/huntlabs/SmartRef


Very nice. Do you have a dub package for this?


Re: SmartRef: The Smart Pointer In D

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-announce
On Saturday, 14 January 2017 at 15:41:01 UTC, Dmitry Olshansky 
wrote:
That is C++ smart_ptr has to be atomic, while its D counter 
part may safely be non-atomic because everything is TLS be 
default.


I assume you mean std::shared_ptr. The reference counting 
semantics are atomic, but the I don't think the compiler is 
required to if it provably isn't shared. There are also ways to 
get around it if needed (you only need atomic count when you 
enter or leave a context, e.g. thread).


Of course, there are C++ single threaded alternatives with 
intrusive ref counting, which I believe is what D is going for. 
shared_ptr is non-intrusive (doesn't affect allocation or object 
types).


Re: SmartRef: The Smart Pointer In D

2017-01-16 Thread biozic via Digitalmars-d-announce

On Monday, 16 January 2017 at 01:54:35 UTC, Dsby wrote:

On Sunday, 15 January 2017 at 17:24:25 UTC, biozic wrote:

On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote:
and : In 
https://github.com/dlang/phobos/blob/master/std/typecons.d#L147

~this()
{
debug(Unique) writeln("Unique destructor of ", (_p is 
null)? null: _p);

if (_p !is null) destroy(_p);
_p = null;
}
 if the 'T' is a struct, it will not exec the Destory 
function. Is it a bug?


What do you mean? This works for me:
---
import std.stdio, std.typecons;

struct Foo {
~this() {
writeln("I'm destroyed");
}
}

void main() {
Unique!Foo foo = new Foo;
} // Prints "I'm destroyed"
---


the "writeln("I'm destroyed");" not run the ~this in the Unique 
destroy function.

it run in the app exit , THe GC distroy all memony.
it example can show :
import std.stdio;
import std.typecons;

 struct Foo {
 ~this() {
 writeln("I'm destroyed");
 }
 }

 void fun(){
Unique!Foo foo = new Foo;
writeln("exit the fun.");
 }

 void main() {
 fun();
  writeln("exit the Main.");
 }

It is the printf:
 ~/tmp  rdmd ./type.d


2017年01月16日 星期一 09时50分00秒

exit the fun.
exit the Main.
I'm destroyed
 ~/tmp 

if you use the struct in Unique, the struct's Destory function 
is not run in the Unique destroy, it is also run in the GC 
collet.

I think it is not the Unique should be.


Right, good point. This behaviour is indeed caused by destroy() 
and is not specific to Unique. But it the case of Unique, relying 
on this (undefined?) behaviour of destroy is a bug (a regression).




Re: SmartRef: The Smart Pointer In D

2017-01-15 Thread Dsby via Digitalmars-d-announce

On Sunday, 15 January 2017 at 17:24:25 UTC, biozic wrote:

On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote:
and : In 
https://github.com/dlang/phobos/blob/master/std/typecons.d#L147

~this()
{
debug(Unique) writeln("Unique destructor of ", (_p is 
null)? null: _p);

if (_p !is null) destroy(_p);
_p = null;
}
 if the 'T' is a struct, it will not exec the Destory 
function. Is it a bug?


What do you mean? This works for me:
---
import std.stdio, std.typecons;

struct Foo {
~this() {
writeln("I'm destroyed");
}
}

void main() {
Unique!Foo foo = new Foo;
} // Prints "I'm destroyed"
---


the "writeln("I'm destroyed");" not run the ~this in the Unique 
destroy function.

it run in the app exit , THe GC distroy all memony.
it example can show :
import std.stdio;
import std.typecons;

 struct Foo {
 ~this() {
 writeln("I'm destroyed");
 }
 }

 void fun(){
Unique!Foo foo = new Foo;
writeln("exit the fun.");
 }

 void main() {
 fun();
  writeln("exit the Main.");
 }

It is the printf:
 ~/tmp  rdmd ./type.d
  

2017年01月16日 星期一 09时50分00秒

exit the fun.
exit the Main.
I'm destroyed
 ~/tmp 

if you use the struct in Unique, the struct's Destory function is 
not run in the Unique destroy, it is also run in the GC collet.

I think it is not the Unique should be.


Re: SmartRef: The Smart Pointer In D

2017-01-15 Thread biozic via Digitalmars-d-announce

On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote:
and : In 
https://github.com/dlang/phobos/blob/master/std/typecons.d#L147

~this()
{
debug(Unique) writeln("Unique destructor of ", (_p is 
null)? null: _p);

if (_p !is null) destroy(_p);
_p = null;
}
 if the 'T' is a struct, it will not exec the Destory function. 
Is it a bug?


What do you mean? This works for me:
---
import std.stdio, std.typecons;

struct Foo {
~this() {
writeln("I'm destroyed");
}
}

void main() {
Unique!Foo foo = new Foo;
} // Prints "I'm destroyed"
---



Re: SmartRef: The Smart Pointer In D

2017-01-15 Thread Dsby via Digitalmars-d-announce

On Sunday, 15 January 2017 at 15:42:19 UTC, Dsby wrote:

On Saturday, 14 January 2017 at 17:35:09 UTC, Nordlöw wrote:

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.


How do two of these differ from

- https://dlang.org/phobos/std_typecons.html#.RefCounted
- https://dlang.org/phobos/std_typecons.html#.Unique

under

https://dlang.org/phobos/std_typecons.html

?
The RefCount not support class or inteface, and the ref count 
is not atomic , it not thread safe.
The Unique is base of GC. It can not @nogc. And it use the 
'delete' keyword , it will be 
deprcated(http://dlang.org/deprecate.html).


The SmartRef is Base std.experimental.allocator. You can 
control where the memony allocator.
And the smartref.sharedref use the atomic default, you alse can 
not use atomic。 And have the smartref.weakref with sharedref to 
fix circular reference.


Sorry,In the new phobos, THe Unique is not used the 'delete' 
keyword.

But , it only destroy, not free the memony.

and : In 
https://github.com/dlang/phobos/blob/master/std/typecons.d#L147

~this()
{
debug(Unique) writeln("Unique destructor of ", (_p is 
null)? null: _p);

if (_p !is null) destroy(_p);
_p = null;
}
 if the 'T' is a struct, it will not exec the Destory function. 
Is it a bug?


Re: SmartRef: The Smart Pointer In D

2017-01-15 Thread Dsby via Digitalmars-d-announce

On Saturday, 14 January 2017 at 17:35:09 UTC, Nordlöw wrote:

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.


How do two of these differ from

- https://dlang.org/phobos/std_typecons.html#.RefCounted
- https://dlang.org/phobos/std_typecons.html#.Unique

under

https://dlang.org/phobos/std_typecons.html

?
The RefCount not support class or inteface, and the ref count is 
not atomic , it not thread safe.
The Unique is base of GC. It can not @nogc. And it use the 
'delete' keyword , it will be 
deprcated(http://dlang.org/deprecate.html).


The SmartRef is Base std.experimental.allocator. You can control 
where the memony allocator.
And the smartref.sharedref use the atomic default, you alse can 
not use atomic。 And have the smartref.weakref with sharedref to 
fix circular reference.


Re: SmartRef: The Smart Pointer In D

2017-01-14 Thread Martin Nowak via Digitalmars-d-announce
On 01/14/2017 04:41 PM, Dmitry Olshansky wrote:
> Not quite true, there is at least one huge advantage - thread-locality.
> That is C++ smart_ptr has to be atomic, while its D counter part may
> safely be non-atomic because everything is TLS be default.

And you can add a shared postblit overload for when it's not thread
local ;).


Re: SmartRef: The Smart Pointer In D

2017-01-14 Thread Nordlöw via Digitalmars-d-announce

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.


How do two of these differ from

- https://dlang.org/phobos/std_typecons.html#.RefCounted
- https://dlang.org/phobos/std_typecons.html#.Unique

under

https://dlang.org/phobos/std_typecons.html

?


Re: SmartRef: The Smart Pointer In D

2017-01-14 Thread Chris Wright via Digitalmars-d-announce
On Sat, 14 Jan 2017 11:52:34 +, nbro wrote:
> Garbage collection in D is more expensive just because of the poor
> implementation, from what I've heard. If that's the case, people who
> work on it should be able to improve it over time.

I posted about this in general.

A GC for Java, Python, Ruby, etc can locate type information and GC 
metadata for an allocation in O(1) time. D's can locate type information 
and GC metadata in O(log N) time in the worst case, even with the best 
possible implementation, and its design decisions make the worst case 
incredibly common. That is one of the common operations that a GC does, 
so it has a big performance impact.

D's GC must be slower because it allows pointers to arbitrary places 
inside an allocation, and it strongly encourages this with array slicing.


Re: SmartRef: The Smart Pointer In D

2017-01-14 Thread nbro via Digitalmars-d-announce

On Saturday, 14 January 2017 at 04:14:11 UTC, Chris Wright wrote:


It's reference counting.

Reference counting is like garbage collection, but deamortized. 
This is better for real-time applications. However, it adds 
overhead on every assignment and every variable going out of 
scope.


In D, garbage collection is more expensive than it is in other 
languages, so the tradeoff is more attractive than it would be 
in other languages.


Garbage collection in D is more expensive just because of the 
poor implementation, from what I've heard. If that's the case, 
people who work on it should be able to improve it over time.




Re: SmartRef: The Smart Pointer In D

2017-01-13 Thread Chris Wright via Digitalmars-d-announce
On Sat, 14 Jan 2017 02:05:11 +, nbro wrote:

> On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:
>> I write the ref count pointer and the scoped point in D. it just Like
>> cpp's shared_ptr , waek_ptr and unique_ptr .
>> Now, it is  Developing.
>> I will write more test before the frist release.
>> And the docs is null.
>> It on github: https://github.com/huntlabs/SmartRef
> 
> What's would be the advantages of smart pointers in D?

It's reference counting.

Reference counting is like garbage collection, but deamortized. This is 
better for real-time applications. However, it adds overhead on every 
assignment and every variable going out of scope.

In D, garbage collection is more expensive than it is in other languages, 
so the tradeoff is more attractive than it would be in other languages.


Re: SmartRef: The Smart Pointer In D

2017-01-13 Thread Swoorup Joshi via Digitalmars-d-announce

On Saturday, 14 January 2017 at 02:05:11 UTC, nbro wrote:

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.
it just Like cpp's shared_ptr , waek_ptr and unique_ptr .
Now, it is  Developing.
I will write more test before the frist release.
And the docs is null.
It on github: https://github.com/huntlabs/SmartRef


What's would be the advantages of smart pointers in D?


Simple, Same Advantages you would get with C++ smart pointers.


Re: SmartRef: The Smart Pointer In D

2017-01-13 Thread nbro via Digitalmars-d-announce

On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote:

I write the ref count pointer and the scoped point in D.
it just Like cpp's shared_ptr , waek_ptr and unique_ptr .
Now, it is  Developing.
I will write more test before the frist release.
And the docs is null.
It on github: https://github.com/huntlabs/SmartRef


What's would be the advantages of smart pointers in D?


SmartRef: The Smart Pointer In D

2017-01-13 Thread Dsby via Digitalmars-d-announce

I write the ref count pointer and the scoped point in D.
it just Like cpp's shared_ptr , waek_ptr and unique_ptr .
Now, it is  Developing.
I will write more test before the frist release.
And the docs is null.
It on github: https://github.com/huntlabs/SmartRef