vorner / bumpalo-herd

Trying to create Sync bump allocator
Apache License 2.0
28 stars 6 forks source link

Provide feature to use nightly allocator API #6

Open NOBLES5E opened 4 years ago

NOBLES5E commented 4 years ago

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.

vorner commented 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?

NOBLES5E commented 4 years ago

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

NOBLES5E commented 3 years ago

@vorner bumpalo has merged allocator API: https://github.com/fitzgen/bumpalo/pull/92

vorner commented 3 years ago

Nice :-). Do you want to give the PR a try?

wackbyte commented 1 year ago

I think I'll try to add this :)

wackbyte commented 1 year ago

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.

vorner commented 1 year ago

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?

wackbyte commented 1 year ago

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.

vorner commented 1 year ago

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.

simnalamburt commented 1 month ago

@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.

References
ejmount commented 1 day ago

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?

simnalamburt commented 1 day ago

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()