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
203 stars 9 forks source link

API inconsistency #104

Closed ghost closed 1 year ago

ghost commented 1 year ago

According to the https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#required-methods, Allocator::alocate on success returns NonNull<[u8]>, butAllocator::deallocate takes NonNull<u8> instead of NonNull<[u8]>. It looks inconsistent. Is it design problem or there are something that I misunderstood?

CAD97 commented 1 year ago

So the reason for this is that the allocation size is given to deallocate in Layout. allocate returns NonNull<[u8]> because it could give you more memory than requested.

ghost commented 1 year ago

Thank you, that makes sense.