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

Add best-effort owns method? #52

Closed
lachlansneff opened this issue Apr 13, 2020 · 2 comments
Closed

Add best-effort owns method? #52

lachlansneff opened this issue Apr 13, 2020 · 2 comments

Comments

@lachlansneff
Copy link

AllocRef should have an owns method for determining if a particular allocation came from specific allocation. Obviously, many allocators couldn't know for sure, so it would have to be best effort.

fn owns(&self, ptr: NonNull<u8>, layout: Layout) -> bool;

or

pub enum Owns {
    Yes,
    Maybe,
}

fn owns(&self, ptr: NonNull<u8>, layout: Layout) -> Owns;

This could be very useful for implementing combinatorial allocators, like in https://www.youtube.com/watch?v=LIb3L4vKZ7U.

@Amanieu
Copy link
Member

Amanieu commented Apr 13, 2020

This was previously discussed here: rust-lang/rust#44302

The conclusion was that it isn't implementable (or at least not efficiently) for the majority of allocator designs. This is best left to a separate trait for allocators that specifically support composability.

@lachlansneff
Copy link
Author

Ah, that makes sense.

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

2 participants