bumpalo icon indicating copy to clipboard operation
bumpalo copied to clipboard

Add custom allocator support for Bump

Open EliaGeretto opened this issue 3 years ago • 4 comments

This pull requests adds support for specifying a custom allocator that Bump should use to allocate new chunks. This should provide a reasonable interface for situations in which memory should not be retrieved from the Global allocator and swapping the whole allocator using #[global_allocator] is not possible.

I have taken care to make this compile both with nightly and stable Rust, albeit some nasty generics workarounds were necessary.

This PR should, ideally, solve #100.

EliaGeretto avatar Jun 16 '21 16:06 EliaGeretto

Could you please tell me if you would be willing to merge this and, in that case, provide some comments?

EliaGeretto avatar Jun 16 '21 16:06 EliaGeretto

Thanks for making this pull request and giving us an idea of what changes are required to support generic backing allocators in bumpalo.

Could you please tell me if you would be willing to merge this and, in that case, provide some comments?

Unlike implementing the allocator API, this support for being parameterized by an allocator is rather invasive with all those cfgs. Therefore, I'd prefer to wait until the allocator API stabilizes -- and bumpalo can always be parameterized by an allocator, rather than only being parameterized in some build configurations -- before adding this support.

fitzgen avatar Jun 21 '21 17:06 fitzgen

I can understand. I need this for my own project, so I am planning to keep my branch reasonably up-to-date. I will leave the PR here in case someone else needs this functionality.

EliaGeretto avatar Jun 21 '21 18:06 EliaGeretto

I am not sure why, but to compile correctly my code requires at least Rust 1.48.

EliaGeretto avatar Jun 21 '21 19:06 EliaGeretto