Function xila_memory_reallocate

Source
#[no_mangle]
pub unsafe extern "C" fn xila_memory_reallocate(
    pointer: *mut c_void,
    size: usize,
) -> *mut c_void
Expand description

Reallocates a memory block to a new size.

This function changes the size of a previously allocated memory block. If the new size is larger, the additional memory is uninitialized. If the new size is smaller, the excess memory is freed. The original data is preserved up to the minimum of the old and new sizes.

§Safety

  • If Pointer is not null, it must have been returned by a previous call to xila_memory_allocate or xila_memory_reallocate
  • The pointer must not be used after this function returns (use the returned pointer instead)
  • If the function returns null, the original pointer remains valid

§Parameters

  • Pointer - Pointer to the memory block to reallocate, or null for new allocation
  • Size - New size in bytes (0 is equivalent to deallocation)

§Returns

  • Pointer to the reallocated memory block
  • Null if allocation fails or if size is 0
  • If Pointer is null, behaves like xila_memory_allocate with default alignment

§Examples

// Allocate initial memory
void* ptr = xila_memory_reallocate(NULL, 1024);

// Expand the memory
ptr = xila_memory_reallocate(ptr, 2048);

// Shrink the memory
ptr = xila_memory_reallocate(ptr, 512);

// Free the memory
xila_memory_reallocate(ptr, 0);