#[no_mangle]
pub unsafe extern "C" fn nstd_alloc_allocate(
    size: NSTDUInt
) -> NSTDAnyMut
Available on crate feature alloc only.
Expand description

Allocates a block of memory on the heap. The number of bytes to be allocated is specified by size.

Parameters:

  • NSTDUInt size - The number of bytes to allocate on the heap.

Returns

NSTDAnyMut ptr - A pointer to the allocated memory, null on error.

Safety

  • Behavior is undefined if size is zero.

  • The new memory buffer should be considered uninitialized.

Example

use nstd_sys::alloc::{nstd_alloc_allocate, nstd_alloc_deallocate};

unsafe {
    let mut mem = nstd_alloc_allocate(32);
    assert!(!mem.is_null());
    nstd_alloc_deallocate(&mut mem, 32);
}