2 ms·
Here OP is implementing a full allocator and something close to a new abstract layer of virtual memory backed by vectors and addressed by offsets. For some use
by oersted 6mo ago
Here OP is implementing a full allocator and something close to a new abstract layer of virtual memory backed by vectors and addressed by offsets.
For some use-cases, you will probably keep all dynamically allocated objects in this memory.
At that point you have circumvented most of Rust’s protections and ergonomics. The user will effectively be working with raw pointers into this memory. The implementation itself also doesn’t have the proper checks because it is manipulating indexes instead of pointers.
The post itself notes around the end how it is fairly easy to end up with a dangling pointer or one that points to a different object allocated to the same position after the old one was freed. It also has quite a few places where it can panic. And implementing its Trace trait wrong or not using Roots as intended can have complex consequences. And all that while feeling like this is the most safe GC because it has no unsafe.
I don’t disagree with anything you said, and I also quite like the work from OP. But I hope you can see that this is not fully aligned with Rust’s philosophy.