-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Alloc: Add owns method #44302
Copy link
Copy link
Closed
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
As Andrei Alexandrescu discusses in this great talk, in order to make it possible to construct new allocators by composing existing ones, each allocator must support an ownership check.
Consider, for example, a "fallback allocator" - an allocator which operates by wrapping two other allocators, serving allocation requests by trying to allocate from the first allocator and falling back to the second one if the first request fails. In Rust:
In order to service deallocation requests to this allocator, however, you need to be able to detect which allocator a given pointer came from. If we assume an
ownsmethod, this looks like:As Andrei discusses in that talk, modern allocators are nothing but composition - size classes, different allocation strategies, falling back to
mmapfor certain allocations, etc. Thus, I think that it's important that we take composability seriously, and ensure that ourAlloctrait is composable. This requires adding anownsmethod. Concretely, I'm suggesting the following signature be added to theAlloctrait:cc @Ericson2314 @pnkfelix @alexcrichton