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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OwnedMmap
impl RefUnwindSafe for OwnedMmap
impl !Send for OwnedMmap
impl !Sync for OwnedMmap
impl Unpin for OwnedMmap
impl UnwindSafe for OwnedMmap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more