nstd_alloc_deallocate

Function nstd_alloc_deallocate 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nstd_alloc_deallocate( ptr: NSTDAnyMut, layout: NSTDAllocLayout, ) -> NSTDAllocError
Available on crate feature alloc only.
Expand description

Deallocates memory that was previously allocated by this allocator.

§Parameters:

  • NSTDAnyMut ptr - A pointer to the allocated memory.

  • NSTDAllocLayout layout - Describes the layout of memory that ptr points to.

§Returns

NSTDAllocError errc - The allocation operation error code.

§Safety

  • Behavior is undefined if ptr is not a pointer to memory allocated by this allocator.

  • layout must be the same value that was used to allocate the memory buffer.

§Example

use nstd_sys::{
    alloc::{nstd_alloc_allocate, nstd_alloc_deallocate},
    core::alloc::{nstd_core_alloc_layout_new, NSTDAllocError::NSTD_ALLOC_ERROR_NONE},
};

unsafe {
    let layout = nstd_core_alloc_layout_new(24, 1).unwrap();
    let mem = nstd_alloc_allocate(layout);
    assert!(!mem.is_null());
    assert!(nstd_alloc_deallocate(mem, layout) == NSTD_ALLOC_ERROR_NONE);
}