#[no_mangle]
pub extern "C" fn nstd_heap_ptr_get_mut(
hptr: &mut NSTDHeapPtr<'_>,
) -> NSTDAnyMut
Available on crate feature
heap_ptr
only.Expand description
Returns a 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:
NSTDHeapPtr *hptr
- The heap pointer.
§Returns
NSTDAnyMut 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_mut, nstd_heap_ptr_new},
};
unsafe {
let v = 32964i128;
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 mut hptr = nstd_heap_ptr_new(&NSTD_ALLOCATOR, layout, addr_of!(v).cast()).unwrap();
let hv = nstd_heap_ptr_get_mut(&mut hptr).cast::<i128>();
assert!(*hv == v);
*hv = -46923;
assert!(*hv != v);
}