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?
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.
According to the https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#required-methods,
Allocator::alocate
on success returnsNonNull<[u8]>
, butAllocator::deallocate
takesNonNull<u8>
instead ofNonNull<[u8]>
. It looks inconsistent. Is it design problem or there are something that I misunderstood?