Iterator invalidation is a common memory safety issue where you have two
references being simultaneously used -- one mutable, one immutable. With
multiple mutable references worse errors can happen.

-Manish Goregaokar

On Fri, Sep 19, 2014 at 1:09 PM, silvio <silvio.fris...@gmail.com> wrote:

> Hi Rust,
>
> I've recently tried to investigate rust's claim of being fast and had a
> look at debian shootout.
>
> A particular program I took a looked at is the n-body problem in which
> you have to loop over pairs of bodies to calculate their gravitational
> attraction. What struck me as strange was the number of indexing
> operations.
>
> bodies[i]
> bodies[j]
> bodies[i]
> bodies[j]
> ...
>
> Now I don't know if the compiler is smart enough to optimize this away.
> However, it seems generally impossible to make references.
>
> let mut body_i = bodies.someMethod(i)
> let mut body_j = bodies.someMethod(j)
>
> So how is this usually done?
>
> Why are multiple mutable references to the same object not allowed. To
> achieve safe memory you only need to guarantee that different threads
> don't write/read from/to the same memory location at the same time and
> that is handled via ownership. (borrowed) references & don't have
> ownership. Additionally, you need to ensure that all references not only
> mut are not usable anymore until you can transfer ownership. So, I don't
> understand why mut and not mut are treated differently.
>
> An other small thing. I read that you should always return a type directly.
>
> fn foo(args) -> big_struct
>
> Does this mean that all return values are secretly pointers passed to
> the function except for things that fit into registers?
>
>
> regards
>
> silvio
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to