7 ms·
Another approach is to use a Gc<T> smart pointer: https://docs.rs/gc/latest/gc/ https://docs.rs/gc/latest/gc/ I've used this in an interpreter and it's quite c
by smasher164 2y ago
Another approach is to use a Gc<T> smart pointer: https://docs.rs/gc/latest/gc/ https://docs.rs/gc/latest/gc/
I've used this in an interpreter and it's quite convenient.
- foldr 2y agoNice! This seems way more appealing than every other approach I've seen in this domain.
- celeritascelery 2y agoThat is just using a RefCell under the hood[1] so it is effectively the same trade-offs as the RefCell example from the article. [1]https://docs.rs/gc/0.5.0/src/gc/lib.rs.html#495-498 https://docs.rs/gc/0.5.0/src/gc/lib.rs.html#495-498
- rendaw 2y agoIt doesn't require you to differentiate weak and strong references, so there's no risk of memory leaks due incorrect choice in Gc, unlike Rc IIUC.
- paholg 2y agoNote: the two of you are linking to different crates. Samsara provides a Gc type, but it is not the gc crate.
- celeritascelery 2y agoIt looks like you intended to say that on the sibling comment.
- paholg 2y agoYep! Sorry.
- zozbot234 2y agoYes, garbage collection seems to be the only viable solution for dealing with spaghetti reference graphs in their full generality, including possible cycles. In that context it's worth trying a high-performance concurrent GC implementation such as https://github.com/chc4/samsara https://github.com/chc4/samsara Samsara.