Open NOBLES5E opened 4 years ago
I'm not opposed to having this, under a feature (maybe allocator-api-unstable
or something?). But I don't know when exactly I would get to it (not a feature I'd use myself right now), so would you want to submit a PR?
I gave it a try today, and it seems like we need change on bumpalo
first, and there is already a PR https://github.com/fitzgen/bumpalo/pull/68
@vorner bumpalo
has merged allocator API: https://github.com/fitzgen/bumpalo/pull/92
Nice :-). Do you want to give the PR a try?
I think I'll try to add this :)
Hmm, I don't think it would be possible to implement this in a way to have the allocator shared between threads since the collection must keep a reference to the allocator (Member
is not Sync
; Herd
is, but it cannot provide the exact Bump
the collection was allocated with). However, it would still be nice to have a feature flag that forwards to bumpalo
's own allocator_api
feature flag.
I wonder… the fact we don't remember the exact Bump
, is it a problem? I mean, I'd suspect the deallocate
on the Bump arena is empty, because Bump can't deallocate, it can be only completely cleaned. So, can we just forward all allocation requests to arbitrary subarena?
I checked, and Bump
's implementation of deallocate
checks if the pointer was the last allocation in the arena and reuses the memory if it was.
I see. But it „leaks“ in all the other cases, so we could just leak every time.
Honestly, just forwarding the feature is kind of… not really much useful. You can always just list both bumpalo and bumpalo-herd in the Cargo.toml, the former with the feature.
@vorner @wackbyte I’ve created a proof of concept (PoC) for implementing the Allocator API. I would appreciate it if you could review it and share your thoughts.
I am also interested in being able to use a Member as an allocator for other collections, and #15 looked exactly what would be needed to be able to do that. Would someone be able to explain why that was closed?
https://github.com/vorner/bumpalo-herd/pull/15#pullrequestreview-2411873462 This was the reason.
If you need Member as an allocator, you can just use Member::as_bump()
In latest Rust nightly we can allocate with custom allocator (for example https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html#method.new_in).
It will be great for bumpalo-herd to provide the ability to use this. To achieve this, we need to implement
std::alloc::AllocRef
.See also https://github.com/fitzgen/bumpalo/issues/87.