Provide feature to use nightly allocator API
NOBLES5E opened this issue · comments
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 fitzgen/bumpalo#87.
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 fitzgen/bumpalo#68
@vorner bumpalo
has merged allocator API: fitzgen/bumpalo#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.