pub struct OwnedMmap(pub *mut c_void, pub usize);Expand description
A safe wrapper for a memory-mapped region.
This struct owns the memory-mapped pointer and ensures that munmap is called
when it goes out of scope, preventing memory leaks.
Tuple Fields§
§0: *mut c_voidA raw pointer to the beginning of the memory-mapped area.
1: usizeThe total size of the memory-mapped area in bytes.
Implementations§
Source§impl OwnedMmap
impl OwnedMmap
Sourcepub fn new(ptr: *mut c_void, size: usize) -> Self
pub fn new(ptr: *mut c_void, size: usize) -> Self
Constructs a new OwnedMmap from a raw pointer and size.
This is a low-level constructor. Prefer mmap for new allocations.
Sourcepub fn mmap(size: usize, huge_page: Option<bool>) -> Result<Self, Error>
pub fn mmap(size: usize, huge_page: Option<bool>) -> Result<Self, Error>
Creates a new memory-mapped region.
This function allocates a new anonymous, private memory-mapped region suitable for use as a UMEM. It can optionally be backed by huge pages.
§How it works
It first determines whether to use huge pages. If huge_page is None, it
checks /proc/meminfo for available huge pages. It then calculates the
required size aligned to the page size (standard or huge) and calls libc::mmap
with the appropriate flags (MAP_HUGETLB if using huge pages).
On success, it returns an OwnedMmap that manages the allocated memory.
Sourcepub fn as_void_ptr(&self) -> *mut c_void
pub fn as_void_ptr(&self) -> *mut c_void
Returns the raw pointer to the memory-mapped region.