#[unsafe(no_mangle)]pub extern "C" fn nstd_shared_ptr_owners(
shared_ptr: &NSTDSharedPtr<'_>,
) -> NSTDUIntAvailable on crate feature
shared_ptr only.Expand description
Returns the number of pointers that share shared_ptr’s data.
§Parameters:
const NSTDSharedPtr *shared_ptr- An instance of a shared pointer.
§Returns
NSTDUInt owners - The number of pointers that share shared_ptr’s data.
§Example
use core::ptr::addr_of;
use nstd_sys::{
alloc::NSTD_ALLOCATOR,
core::alloc::nstd_core_alloc_layout_new,
shared_ptr::{
nstd_shared_ptr_get, nstd_shared_ptr_new, nstd_shared_ptr_owners, nstd_shared_ptr_share,
},
};
const SIZE: usize = core::mem::size_of::<i128>();
unsafe {
let v = i128::MIN;
let share;
{
let size = core::mem::size_of::<i128>();
let align = core::mem::align_of::<i128>();
let layout = nstd_core_alloc_layout_new(size, align).unwrap();
let addr = addr_of!(v).cast();
let shared_ptr = nstd_shared_ptr_new(&NSTD_ALLOCATOR, layout, addr).unwrap();
assert!(nstd_shared_ptr_owners(&shared_ptr) == 1);
share = nstd_shared_ptr_share(&shared_ptr);
assert!(nstd_shared_ptr_owners(&shared_ptr) == 2);
let temp = nstd_shared_ptr_share(&shared_ptr);
assert!(nstd_shared_ptr_owners(&temp) == 3);
}
assert!(nstd_shared_ptr_owners(&share) == 1);
assert!(*nstd_shared_ptr_get(&share).cast::<i128>() == v);
}