Why does D rely on a GC?

Peter Alexander via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 18 05:55:50 PDT 2014


On Monday, 18 August 2014 at 12:06:27 UTC, Kagamin wrote:
> On Monday, 18 August 2014 at 10:01:59 UTC, maik klein wrote:
>> Does a GC still have advantages over heap allocations that do 
>> not need to be reference counted such as the unique_ptr in c++?
>
> Isn't unique_ptr unique? What to do when the object is 
> non-unique?

Yes, unique_ptr is unique :-)  It is not reference counted -- it 
just destroys the owned object when it goes out of scope. The 
near thing about unique_ptrs is that you can move them around, 
transferring ownership.

If the object is non-unique, then typically C++ programmers will 
use shared_ptr (+ weak_ptr).

I'm not sure what the status of std.typecons.Unique is. Last I 
heard it had some issues, but I haven't tried it much myself.


More information about the Digitalmars-d mailing list