RCArray is unsafe
weaselcat via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 2 15:47:55 PST 2015
On Monday, 2 March 2015 at 22:51:03 UTC, Walter Bright wrote:
> On 3/2/2015 1:12 PM, deadalnix wrote:
>> I do think you are confusing how Rust does it. In Rust,
>> borrowing makes the
>> source and borrowed reference immutable by default. So by
>> default the problem do
>> not occurs.
>
> May I refer you to:
>
> http://static.rust-lang.org/doc/0.6/tutorial-borrowed-ptr.html#borrowing-managed-boxes-and-rooting
>
> "Again the lifetime of y is L, the remainder of the function
> body. But there is a crucial difference: suppose x were to be
> reassigned during the lifetime L? If the compiler isn't
> careful, the managed box could become unrooted, and would
> therefore be subject to garbage collection. A heap box that is
> unrooted is one such that no pointer values in the heap point
> to it. It would violate memory safety for the box that was
> originally assigned to x to be garbage-collected, since a
> non-heap pointer---y---still points into it.
> [...]
> For this reason, whenever an & expression borrows the interior
> of a managed box stored in a mutable location, the compiler
> inserts a temporary that ensures that the managed box remains
> live for the entire lifetime. [...] This process is called
> rooting."
>
>
> It's possible that this is an old and obsolete document, but
> it's what I found.
That's actually very old(0.6 - nearly 2 years ago.) I believe
rooting was dropped from the language completely.
http://doc.rust-lang.org/book/ownership.html
also, rust by example chapter 17-19 cover this
http://rustbyexample.com/move.html
More information about the Digitalmars-d
mailing list