fitzgen / bumpalo

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

Allow creation of allocator from slice #100

Closed vinaychandra closed 8 months ago

vinaychandra commented 3 years ago

The current new methods use Global allocator for the allocator to work with. Provide an unsafe way to create a bump allocator which will allow to create the allocator from a slice denoting unused memory.

fitzgen commented 3 years ago

It is a pretty fundamental assumption in this implementation that chunks of memory come from the global allocator, that we can request new chunks as needed, and that we deallocate the chunks when the Bump itself is deallocated.

Changing this assumption would require either dynamic checks or making the whole crate parameterized by another allocator (which would dole out portions of a given slice for your requested feature). The first option is unacceptable. The second is possible, but would require some care and thought, and I'm not totally sure would be worth it or not. I also don't have the cycles to explore the second option right now.

The easiest thing to do for your use case would probably be to write a specialized crate for exactly what you're trying to do (possibly forking/borrowing code from this crate).