5 ms·
No, 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);
by ridiculous_fish 6y ago
No, 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 6y 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 6y 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.