Open TimDiekmann opened 4 years ago
Some notes on ZST handling for used allocators in std:
0
on zero-sized allocationsHeapAlloc
. Documentation does not mention, how it behaves on zero-sized allocation.Even a request for zero bytes (i.e., malloc(0)) returns a pointer to something of the minimum allocatable size [...] typically 4096 or 8192 bytes.
malloc
-like API, implementation definedSo supporting ZST will not change anything, we have to check for ZSTs ourself.
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
.
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.
Currently,
System as AllocRef
calls theGlobalAlloc
implementation.GlobalAlloc
forSystem
is implemented instd::sys::*::alloc
. I'd like to swap this for two reasons:AllocRef
has more methods likegrow_in_place
. At leastdlmalloc
supports this.System
makes more sense to be implemented instd::sys::*::alloc
.