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
locationmust exactly match the start of the memory range reserved viaalloc, andsizeis ignored. - On Unix, you can unreserve a subrange, i.e.
locationandsizemust be currently reserved, but do not need to match exactly match the memory range reserved viaalloc.
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())? };