pub unsafe fn rezalloc(p: *mut u8, new_size: usize) -> *mut u8Expand description
Grow or shrink an allocation, zeroing any newly-exposed tail.
Thin wrapper around mi_rezalloc. This is the operation Rust’s GlobalAlloc
cannot express — that trait has no grow_zeroed — so without it a caller has to
grow and then memset by hand, repeating work the allocator has already done, and
(with zero-tracking) work it may be able to skip entirely.
§What is actually zeroed
Not [old_requested_size, new_size). mimalloc measures from the block’s old
usable size, so the slack between what you asked for and what the block actually
holds is left untouched:
requested 64 -> usable 80 -> rezalloc to 70
bytes [64,70) are NOT zeroed: the grow was served in place, within the old blockThe guarantee is: everything past usable_size of the original block is zero.
If you need a specific range zeroed, capture usable_size before the call and
zero the remainder yourself.
(This is documented so precisely because a fuzz harness asserted the intuitive version and was falsified within seconds — see issue #87.)
§Safety
pmust be null, or a pointer from the plain allocation family — the global allocator,sys::mi_malloc, or a previousrezalloc/recalloc— that has not been freed.- Not interchangeable with
unwrapped_malloc/unwrapped_realloc. Those place a header before the pointer, so passing one here fails the pointer check (mi_usable_size: invalid pointer) rather than working by accident. - After this call
pis consumed: do not read, write, or free it again, whether or not the return value is null. - On failure a null pointer is returned and
pis left valid and unfreed.