More radical ideas about gc and reference counting

Tommi via Digitalmars-d digitalmars-d at puremagic.com
Mon May 12 03:27:29 PDT 2014


On Sunday, 11 May 2014 at 21:43:06 UTC, sclytrack wrote:
> I like this owner/unique, borrow thing.
>
> @ is managed (currently reference counted)
> ~ is owner
> & is borrow

I like it too. But a few notes:

1) The managed pointer @T has been deprecated and you should use 
the standard library types Gc<T> and Rc<T> instead.

2) The owned pointer ~T has been largely removed from the 
language and you should use the standard library type Box<T> 
instead.

The basic idea is that if a function needs to have ownership of 
its argument, the function should take its argument by value. And 
if the function doesn't need the ownership, it should take its 
argument either by a mutable or immutable reference (they don't 
like to call it "borrowed pointer" anymore, it's called simply a 
"reference" now). Owned types get moved by default when you pass 
them to a function that takes its argument by value. You call the 
'clone' method to make a copy of a variable of an owned type.


More information about the Digitalmars-d mailing list