#[no_mangle]
pub const extern "C" fn nstd_heap_ptr_get(
hptr: &NSTDHeapPtr<'_>,
) -> NSTDAny
Available on crate feature
heap_ptr
only.Expand description
Returns an immutable raw pointer to the object on the heap.
§Note
This will always return null if the size of the object being stored on the heap is 0.
§Parameters:
const NSTDHeapPtr *hptr
- The heap pointer.
§Returns
NSTDAny ptr
- A raw pointer to the object on the heap.
§Example
use core::ptr::addr_of;
use nstd_sys::{
alloc::NSTD_ALLOCATOR,
core::alloc::nstd_core_alloc_layout_new,
heap_ptr::{nstd_heap_ptr_get, nstd_heap_ptr_new},
};
unsafe {
let v = -46923i128;
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 hptr = nstd_heap_ptr_new(&NSTD_ALLOCATOR, layout, addr_of!(v).cast()).unwrap();
assert!(*nstd_heap_ptr_get(&hptr).cast::<i128>() == v);
}