Function nstd_heap_ptr_size

Source
#[no_mangle]
pub const extern "C" fn nstd_heap_ptr_size(
    hptr: &NSTDHeapPtr<'_>,
) -> NSTDUInt
Available on crate feature heap_ptr only.
Expand description

Returns the size of the heap allocated object.

§Parameters:

  • const NSTDHeapPtr *hptr - The heap pointer.

§Returns

NSTDUInt size - The size of the heap allocated object.

§Example

use nstd_sys::{
    alloc::NSTD_ALLOCATOR,
    core::alloc::nstd_core_alloc_layout_new,
    heap_ptr::{nstd_heap_ptr_new_zeroed, nstd_heap_ptr_size},
};

unsafe {
    let size = core::mem::size_of::<i32>();
    let align = core::mem::align_of::<i32>();
    let layout = nstd_core_alloc_layout_new(size, align).unwrap();
    let hptr = nstd_heap_ptr_new_zeroed(&NSTD_ALLOCATOR, layout).unwrap();
    assert!(nstd_heap_ptr_size(&hptr) == size);
}