Skip to main content

dealloc

Function dealloc 

Source
pub unsafe fn dealloc(location: NonNull<u8>, size: usize) -> Result<()>
Expand description

Deallocate previously allocated virtual pages, releasing them to the OS.

This operation is also called “unmapping” or “releasing”.

§Errors

Returns Error::InvalidInput if:

§Safety

For portability, location and size must exactly match the memory range reserved via alloc.

Platform specific:

  • On Windows, only location must exactly match the start of the memory range reserved via alloc, and size is ignored.
  • On Unix, you can unreserve a subrange, i.e. location and size must be currently reserved, but do not need to match exactly match the memory range reserved via alloc.

Undefined behavior if location + size overflows.

§Examples

let ptr = unsafe {
    pagealloc::alloc(
        std::ptr::null_mut(),
        pagealloc::alloc_granularity(),
        pagealloc::Protection::ReadWrite,
    )?
};
// ...
unsafe { pagealloc::dealloc(ptr, pagealloc::alloc_granularity())? };