fitzgen / bumpalo

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

Add a `bumpalo::collections::ThinSlice` type #221

Closed QnnOkabayashi closed 9 months ago

QnnOkabayashi commented 9 months ago

In my project, I've been using the Bump::alloc_slice_* family of methods a lot. Since the returned slices are freshly allocated, why not allow for a ThinSlice type that's just a single pointer into the Bump buffer that points to the length followed by that many elements? It would laid out a lot like ThinVec, but the data is owned by the Bump and with immutable length. You could then have it Deref/DerefMut to a regular slice as well, granting it all the methods and flexibility that slices come with.

For naming, we could just give each alloc_slice_* method a corresponding alloc_thin_slice_* method.

Pros

Cons

I'm happy to discuss or send in a PR for this if it sounds good to you.

fitzgen commented 9 months ago

I agree it is certainly possible to add these methods, but I'm not sure that the pros outweigh the cons here.

That said, I don't think there is any technical reason one couldn't build this on top of bumpalo in an external crate. I'd suggest investigating this route further.

Thanks!