Function std::alloc::realloc

pub fn realloc<T>(ptr: raw_ptr, count: u64, new_count: u64) -> raw_ptr 
Expand description

Reallocates the given area of memory.

Arguments

  • ptr: [raw_ptr] - The pointer to the area of memory to reallocate.
  • count: [u64] - The number of size_of<T> bytes kept when reallocating. These are not set to 0.
  • new_count: [u64] - The number of new size_of<T> bytes to allocate. These are set to 0.

Returns

  • [raw_ptr] - The pointer to the newly reallocated memory.

Examples

use std::alloc::{alloc, realloc};

fn foo() {
    let ptr = alloc::<u64>(1);
    ptr.write(5);
    let reallocated_ptr = realloc::<u64>(ptr, 1, 2);
    assert(reallocated_ptr.read::<u64>() == 5);
}