Skip to main content

unwrapped_realloc

Function unwrapped_realloc 

Source
pub unsafe fn unwrapped_realloc(
    p: *mut u8,
    new_size: usize,
    alignment: usize,
) -> *mut u8
Expand description

Resize a pointer returned by unwrapped_malloc or unwrapped_realloc.

Thin wrapper around mi_unwrapped_realloc (include/mimalloc/memory-events.h). If p is null, this behaves like unwrapped_malloc. If new_size is 0, this frees p (like unwrapped_free) and returns a null pointer. Otherwise the existing contents are copied into a freshly allocated unwrapped block (up to min(old payload size, new_size) bytes) and p is freed; p must not be used again after this call, whether or not it returns null.

Returns a null pointer on failure (including invalid alignment; see unwrapped_malloc’s # Safety section), in which case p is left valid and unfreed.

§Safety

  • p must be either a null pointer or a pointer previously returned by unwrapped_malloc or unwrapped_realloc that has not already been freed, per the same family-isolation rule as unwrapped_free.
  • alignment has the same power-of-two-or-zero contract as unwrapped_malloc.
  • After this call, p must not be read, written, or freed again — treat it as consumed regardless of whether the return value is null.