Hacker News new | ask | show | jobs
by worik 242 days ago
> works well with borrow checking.

Yes, because it defeats borrow checking.

Unsafe Rust, used directly, works too

1 comments

It does not defeat borrow checking. The borrow checker will ensure that objects do not outlive the arena. It works with borrow checking.
The borrow checker knows nothing about your arena allocations.

That is if we are talking about the same thing!

All the borrow checker knows is there is a chunk of memory (the arena) in scope.

It works, no memory safety in the sense that you must manage your own garbage and you can reference uninitialized parts of the arena

I have found myself using arenas in Rust for managing circular references (networks with cycles) and if I were to do it again I think I would write that bit in C or unsafe Rust.

The popular Bumpalo only returns references with the lifetime of the allocator. Not sure what you mean by manage your own garbage, an arena allocator deallocates everything when it goes out of scope. You definitely can't reference uninitialized parts of an arena.
This. Arenas don't work when you don't know when it's okay to free. The borrow checker can help with that (or you can track it manually in C/Zig).