Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime allocators #83

Open
ivannp opened this issue Feb 3, 2021 · 5 comments
Open

Runtime allocators #83

ivannp opened this issue Feb 3, 2021 · 5 comments

Comments

@ivannp
Copy link

ivannp commented Feb 3, 2021

How is the scenario where the allocator is, and can only be, determined at runtime supported? Not too advanced in Rust, so I might be missing something obvious.

I am kind of looking for the equivalent to the C++ 17 polymorphic allocators. In this scenario, the allocator can literally be dropped from the template definition, and it's determined at runtime, via the constructor. This is common scenario in systems using different heaps for different allocations. In these cases, the common scenario is to have a single allocator type, with different runtime configs:

    vector<int> v(my_polimorphic_allocator(theHeap));
@RustyYato
Copy link

RustyYato commented Feb 3, 2021

Given that Allocator is almost object-safe, yes it should. Currently, the only thing holding it back is Allocator::by_ref which uses Self in its signature. If that is given a where Self: Sized bound, then Allocator will become object safe, so you can use it polymorphically.

@Amanieu
Copy link
Member

Amanieu commented Feb 3, 2021

Please do send a PR for this, otherwise we might forget about it before stabilizing Allocator.

@chorman0773
Copy link

Would the allocator type in this case be &dyn Allocator, or something else?

@Amanieu
Copy link
Member

Amanieu commented Feb 3, 2021

&dyn Allocator, Box<dyn Allocator>, Arc<dyn Allocator>, etc.

m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 5, 2021
…Amanieu

Make `Allocator` object-safe

This allows rust-lang/wg-allocators#83: polymorphic allocators
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 5, 2021
…Amanieu

Make `Allocator` object-safe

This allows rust-lang/wg-allocators#83: polymorphic allocators
@RustyYato
Copy link

Since rust-lang/rust#81730 was merged, can this issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants