More radical ideas about gc and reference counting

Paulo Pinto via Digitalmars-d digitalmars-d at puremagic.com
Sun May 11 14:52:34 PDT 2014


Am 11.05.2014 23:43, schrieb sclytrack:
> On Sunday, 11 May 2014 at 11:42:37 UTC, ponce wrote:
>> On Sunday, 11 May 2014 at 08:59:42 UTC, Walter Bright wrote:
>>>
>>> D also cannot be performance competitive with C++ if pervasive ARC is
>>> used and memory safety is retained. Rust is attempting to solve this
>>> problem by using 'borrowed' pointers, but this is unproven
>>> technology, see my reply to Manu about it.
>>
>> I work in a C++ shop and as I see it, resource management is becoming
>> a solved problem:
>>
>> - resource owners holds a std::unique_ptr<T> on them. Resource release
>> is taken care by C++ destructors normally. That means to be
>> exception-safe, each resource type must better have its class.
>> - resource users eventually "borrow" the resource by taking a raw
>> pointer out of the unique pointer. What Rust would do with lifetimes
>> here is ensure that the resource is still there since move semantics
>> seems pervasive in this language. In C++ we ensure the resource holder
>> outlive the users.
>> - std::shared_ptr is not needed with such constraints. This means no
>> cycles in the object graph. TBH I have yet to find a dependency scheme
>> that can't be done that way.
>>
>> When I use D I can't help but think that releasing resources feels
>> more manual and error-prone ("oops that resource should have been a
>> struct not a class" and such traps).
>>
>> I do not have huge concerns about D GC, but I would be glad to have
>> more support for owned pointers (ie. Unique!T in Phobos or better). I
>> have no idea how to make it safe ie. ensure the resource outlive its
>> users.
>
> I like this owner/unique, borrow thing.
>
> @ is managed (currently reference counted)
> ~ is owner
>       & is borrow
>
> fn example3() -> int {
>      let mut x = ~X {f: 3};
>      let y = &x.f;
>      x = ~X {f: 4};  // Error reported here.
>      *y
> }
>
>
> According to Debian Rust is still too experimental to be packaged.
> http://web.mit.edu/rust-lang_v0.8/doc/tutorial-borrowed-ptr.html
>
>
> servo is written in Rust.
> https://github.com/mozilla/servo
>
> There is very little use of "@", it's mostly  "&" and "~". Heck I didn't
> find any @ while casually browsing the code. It's like they are not
> using it at all.
>
> I don't know Rust, it is the first day I look (read documentation) at it.
>

Have you searched for RC<>() and GC<>() as well?

The @ is gone from Rust and replaced by library types.

--
Paulo



More information about the Digitalmars-d mailing list