I have a pointer buf: *const T
pointing to the start of an allocation of n
elements of T
, and I define the following check:
let in_alloc = buf <= ptr && ptr < unsafe { buf.add(n) };
Is it guaranteed that in_alloc
is true
for any ptr
that lies in the allocation of buf
, and false
in any other case? We may assume that ptr
is a valid pointer to a T
object (so not misaligned/null/dangling), however it may or may not be from the same allocation as buf
. Finally we may assume T
is not zero-sized.