fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.39k stars 110 forks source link

Are references still stable if the Bump is moved? #96

Closed jkelleyrtp closed 3 years ago

jkelleyrtp commented 3 years ago

Asking this because I'd like to store references into the bump along with the bump itself via OwningRef (or by raw pointer directly).

let bumps = Vec<OwningRef<Bump, T>>;
// or, more unsafely but more efficient
let bumps = Vec<(Bump, Vec<*mut T>)>;

If bumps grows then it will need to be resized. Will the references into the bump remain stable, meaning it's still okay to cast *mut T back to &mut T?

If not, how would you go about stably storing the bump alongside objects it has allocated?

I know Dodrio does this for CachedNodes, but I can't help but think that that particular implementation is unsound if the CachedNodes Fxhashmap needs to be resized.

fitzgen commented 3 years ago

Yes references are stable. There is no inline storage space within a Bump and the allocated storage never moves.

If bumps grows then it will need to be resized. Will the references into the bump remain stable, meaning it's still okay to cast *mut T back to &mut T?

Existing storage space is never resized, new chunks are allocated.