Function nstd_sys::shared_ptr::nstd_shared_ptr_new
source · #[no_mangle]
pub unsafe extern "C" fn nstd_shared_ptr_new(
element_size: NSTDUInt,
init: NSTDAny
) -> NSTDSharedPtrAvailable on crate feature
nstd_shared_ptr only.Expand description
Creates a new initialized instance of a shared pointer.
Parameters:
-
NSTDUInt element_size- The size of the shared object. -
NSTDAny init- A pointer to the object to initialize the shared pointer with.
Returns
NSTDSharedPtr shared_ptr - The new shared pointer.
Panics
This operation will panic if either element_size is greater than NSTDInt’s max value or
allocating fails.
Safety
init must be a pointer to a value that is valid for reads of element_size bytes.
Example
use core::ptr::addr_of;
use nstd_sys::shared_ptr::{nstd_shared_ptr_get, nstd_shared_ptr_new};
const SIZE: usize = core::mem::size_of::<i16>();
let v = i16::MIN;
unsafe {
let shared_ptr = nstd_shared_ptr_new(SIZE, addr_of!(v).cast());
assert!(*nstd_shared_ptr_get(&shared_ptr).cast::<i16>() == v);
}