Function nstd_sys::shared_ptr::nstd_shared_ptr_new_zeroed
source · #[no_mangle]
pub unsafe extern "C" fn nstd_shared_ptr_new_zeroed(
allocator: &NSTDAllocator,
element_size: NSTDUInt
) -> NSTDOptionalSharedPtr<'_>Available on crate feature
shared_ptr only.Expand description
Creates a new zero-initialized instance of a shared pointer.
Parameters:
-
const NSTDAllocator *allocator- The memory allocator. -
NSTDUInt element_size- The size of the shared object.
Returns
NSTDOptionalSharedPtr shared_ptr - The yet to be shared pointer, or an uninitialized “none”
variant if allocating fails.
Safety
The data to be stored in the shared pointer must be safely representable by an all-zero byte pattern.
Example
use nstd_sys::{
alloc::NSTD_ALLOCATOR,
shared_ptr::{nstd_shared_ptr_get, nstd_shared_ptr_new_zeroed},
};
const SIZE: usize = core::mem::size_of::<u128>();
unsafe {
let shared_ptr = nstd_shared_ptr_new_zeroed(&NSTD_ALLOCATOR, SIZE).unwrap();
assert!(*nstd_shared_ptr_get(&shared_ptr).cast::<u128>() == 0);
}