Function nstd_sys::shared_ptr::nstd_shared_ptr_new_zeroed
source · #[no_mangle]
pub extern "C" fn nstd_shared_ptr_new_zeroed(
element_size: NSTDUInt
) -> NSTDSharedPtrAvailable on crate feature
nstd_shared_ptr only.Expand description
Creates a new zero-initialized instance of a shared pointer.
Parameters:
NSTDUInt element_size- The size of the shared object.
Returns
NSTDSharedPtr shared_ptr - The yet to be shared pointer.
Panics
This operation will panic if either element_size is greater than NSTDInt’s max value or
allocating fails.
Example
use nstd_sys::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(SIZE);
assert!(*nstd_shared_ptr_get(&shared_ptr).cast::<u128>() == 0);
}