borrowed pointers vs ref
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 13 13:46:19 PDT 2014
On 5/13/2014 12:06 PM, Dicebot wrote:
> No, it still can be necessary. `scope` can greatly help not only with resource
> releasing, it is also missing tool to safely cast from shared. Locking shared
> variable can return same variable casted to scope qualifier which will
> guarantee that no reference has been stored to shared object by the time lock
> is released.
I believe that is the role of `unique`. DIP69 addresses making unique pointers
in D, and there have been several PR's implementing aspects of it.
> And "if those are marked as refcounted" as assumption is no better than "if
> those are owned by GC" ;)
I think that an object that wants to completely own its resources must properly
encapsulate and restrict unsafe access to them itself.
> Also A can only control escaping of any internal references only by completely
> prohibiting access to it which is not good. You have no means to say "feel free
> to use this reference as long as you don't keep it outside of current scope".
> And you effectively say "make all your array members private to keep borrowing
> guarantees".
You can by only returning ref's.
More information about the Digitalmars-d
mailing list