pub unsafe extern "C" fn xila_memory_reallocate(
pointer: *mut c_void,
size: usize,
) -> *mut c_voidExpand 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
Pointeris not null, it must have been returned by a previous call toxila_memory_allocateorxila_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 allocationSize- 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
Pointeris null, behaves likexila_memory_allocatewith 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);