Pre-RFC: changing the Alloc trait

FWIW http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0901r0.html was discussed with the jemalloc devs in the C++ Jacksonville meeting and they’ve agreed to experimentally try to offer an API that always returns the Excess.

IMO at this point I am back to my initial opinion that all allocator methods should always return the Excess. We can always write a wrapper in a crate that just drops it “for convenience” but that doesn’t need to be part of std and it simplifies the API in std. That would allow us to kill usable_size , and half of the Alloc trait API.

Allocators that don’t know the Excess can just dummily return the requested size.

Allocators that don’t know the Excess when allocating, but have a separate usable_size method internally can just call it in such a way that the computation is optimized away if the Excess is not used, or just provide to implementations of the Alloc API for their allocator, one doing that, and one just returning the requested size. That is, they can provide two newtypes MyAlloc, MyAllocAccurate, with two different implementations if they want.

Allocators that do know the Excess when allocating can just return it.

1 Like