Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 13, 2017 SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
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 |
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dsby | 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?
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nbro | 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.
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nbro | On Sat, 14 Jan 2017 02:05:11 +0000, 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.
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Wright | 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.
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nbro | On Sat, 14 Jan 2017 11:52:34 +0000, 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.
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Swoorup Joshi | On 1/14/17 3:20 AM, Swoorup Joshi wrote:
> 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.
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.
Of course, there is a place for smart pointer shared across threads, but I'd personally go with message passing instead.
---
Dmitry Olshansky
|
January 14, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dsby | 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 ? |
January 15, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | 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 ;).
|
January 15, 2017 Re: SmartRef: The Smart Pointer In D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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. |
Copyright © 1999-2021 by the D Language Foundation