vorner / bumpalo-herd

Trying to create Sync bump allocator
Apache License 2.0
26 stars 4 forks source link

Provide feature to use nightly allocator API #6

Open NOBLES5E opened 3 years ago

NOBLES5E commented 3 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 3 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 3 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 10 months ago

I think I'll try to add this :)

wackbyte commented 10 months 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 10 months 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 10 months 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 10 months 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.