Change parameters of AllocRef
to take NonNull<[u8]>, usize
instead of NonNull<u8>, Layout
#69
Labels
AllocRef
to take NonNull<[u8]>, usize
instead of NonNull<u8>, Layout
#69
Currently,
AllocRef
contains those signatures (leaving out_zeroed
variants):I like to propose to change those to take
NonNull<[u8]>
as they also return a slice. Also this would change theLayout
parameter to take the alignment instead.This would also change the Memory fitting safety section wording a bit:
align
, andptr.len()
must fall in the rangemin ..= max
, where:min
is the size of the layout most recently used to allocate the block, andmax
is the latest actual size returned fromalloc
,grow
, orshrink
.The first condition implies, that the alignment has to meet the
Layout::from_size_align
requirements.The main advantage is, that one can simply pass a returned pointer back to the allocator, which will always fit the memory block. While this don't lift any safety conditions, it's more safe to use it. For structs storing only a
NonNull<T>
(likeBox
), aNonNull<[T]>
can still be constructed withNonNull::slice_from_raw_parts(self.0, mem::align_of::<T>())
, regardless of the returnedptr.len()
, as it was requested withLayout::new<T>()
.A minor downside are the parameters in
grow
andshrink
as they take twousize
s in a row. While the parameter order should be intuitive, this would be resolved, if we decide to allow reallocation to a different alignment (#5). Then, those methods would look like this:The text was updated successfully, but these errors were encountered: