Alloc-WG
An attempt to collect several proposals of rust-lang/wg-allocators into an MVP.
Changes regarding the current Alloc trait
-
The first thing to notice is, that
Allocwas renamed toAllocRefin order to show that they are typically implemented for a reference or smart pointer or ZST, not directly for the type that actually holds the allocator’s state.Issue on WG repository: rust-lang/wg-allocators#8
-
AllocRefwas split up intoAllocRef,DeallocRef, andReallocRefto make more flexible allocators possible.Issue on WG repository: rust-lang/wg-allocators#9
-
All three traits were associated with a Builder:
BuildAlloc,BuildDealloc, andBuildReallocsuch those traits are related to their association similar howBuildHasheris related toHasher. Although the signatures are different, it makes an even more flexible allocator design possible.Issue on WG repository: rust-lang/wg-allocators#12
-
Add an associative error type to
AllocRef. Besides adding the possibility of returning additional information on allocation failure, it's also possible to split the usage of theAllocRefinto a fallible and an infallible case. Personally I think this is a pretty big deal, as kernel programmer can rely on allocation, which will never fail. If an allocation can fail, only atry_*_inmethod may be available. To maintain backwards compatibility,AbortAllocwas introduced.AbortAllocwraps another allocator, but aborts on OOM thusAbortAlloc<Global>may be used as default allocator forBoxorVec. To realize this,AbortAllocimplementsAllocRef<Error=!>.Issue on WG repository: rust-lang/wg-allocators#23
-
The new layout type
NonZeroLayoutwas introduced. Currently, implementors ofAlloccan chose to allow zero-sized allocation so in a generic context it's impossible to rely on this, so banning zero-sized allocation is a possible step to prevent this. This also removesunsafefromAllocRef::allocandAllocRef::alloc_zeroed, and unlocks the possibility to move the extension API likealloc_arrayinto a separate trait.Issue on WG repository: rust-lang/wg-allocators#16
To Do
- provide a minimal implementation for
Box<T, B: BuildDealloc>. So far I'm basically done with this, but things has to be cleaned up a bit before. - provide a decent documentation for the new traits
License
Alloc-WG is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.