rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
205 stars 9 forks source link

Implement `AllocRef` on `System` without `GlobalAlloc` #43

Open TimDiekmann opened 4 years ago

TimDiekmann commented 4 years ago

Currently, System as AllocRef calls the GlobalAlloc implementation. GlobalAlloc for System is implemented in std::sys::*::alloc. I'd like to swap this for two reasons:

TimDiekmann commented 4 years ago

Some notes on ZST handling for used allocators in std:

So supporting ZST will not change anything, we have to check for ZSTs ourself.

Amanieu commented 4 years ago

As an end-goal, I think we will want to completely replace GlobalAlloc with AllocRef (i.e. #[global_allocator] requires AllocRef instead of GlobalAlloc). This is discussed in more detail in #21. As part of this we will provide a "compatibility wrapper" of impl AllocRef for T where T: GlobalAlloc which implements AllocRef using the GlobalAlloc methods.

So basically, I am in favor of this change since it moves us towards the direction of AllocRef being the "primary" implementation for System.

TimDiekmann commented 4 years ago

I think that we should wait with this change until #38, #41, and #42 are merged (I expect this), otherwise I have to change many files on every push. Falling back to GlobalAlloc is currently quiet convenient.