3 ms·
I’m not sure I follow. Are you suggesting the addition of multiple mutable ownership of values to Rust, managed by a garbage collector?
by saagarjha 7y ago
I’m not sure I follow. Are you suggesting the addition of multiple mutable ownership of values to Rust, managed by a garbage collector?
- ridiculous_fish 7y agoNo, I am talking about writing Rust code that refers to objects on a GC-managed heap. For example, assume v8-ish semantics: let mut cell = allocate(0.0); let counter : &mut f64 = cell.as_mut_ref(); *counter += 1; stuff(); *counter -= 1; Here `stuff()` may trigger further allocations which result in moving `cell`, leaving `counter` dangling.
- saagarjha 7y agoAh. I am not a Rust expert but I think the language might actually support this sort of construct (though it might be inefficient to implement), as IIRC if you want something to stay at a fixed place in memory you need to “pin” it there.
- pirocks 7y agoSurely they way most gcs achieve this is by asking you to tell the gc when you aquire a reference to an object, and tell it again when you no longer need it. You could do that with a custom implementation of drop in rust.