Function nstd_sys::alloc::nstd_alloc_allocate_zeroed
source · #[no_mangle]
pub unsafe extern "C" fn nstd_alloc_allocate_zeroed(
size: NSTDUInt
) -> NSTDAnyMutAvailable on crate feature
alloc only.Expand description
Allocates a block of zero-initialized memory on the heap.
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.
Example
use nstd_sys::alloc::{nstd_alloc_allocate_zeroed, nstd_alloc_deallocate};
const SIZE: usize = core::mem::size_of::<[i16; 16]>();
unsafe {
let mut mem = nstd_alloc_allocate_zeroed(SIZE);
assert!(!mem.is_null());
assert!(*mem.cast::<[i16; 16]>() == [0i16; 16]);
nstd_alloc_deallocate(&mut mem, SIZE);
}