pub struct OwnedReadWriteMmap { /* private fields */ }
Expand description
An owned version of ReadWriteMmap that owns its file handle via Arc, making it safe to send across threads and allowing multiple mappings to share the same handle.
Implementations§
Source§impl OwnedReadWriteMmap
impl OwnedReadWriteMmap
Sourcepub fn handle(&self) -> Arc<ReadWriteFileHandle>
pub fn handle(&self) -> Arc<ReadWriteFileHandle>
Returns a reference to the underlying file handle
Sourcepub unsafe fn new(
handle: Arc<ReadWriteFileHandle>,
offset: u64,
length: usize,
) -> Result<Self, MmapError>
pub unsafe fn new( handle: Arc<ReadWriteFileHandle>, offset: u64, length: usize, ) -> Result<Self, MmapError>
Creates a new owned memory mapping from a file handle.
§Arguments
handle
- The file handle to map, wrapped in an Arc for shared ownershipoffset
- The offset into the file to start the mappinglength
- The length of the mapping
§Safety
This function is unsafe because it creates a new memory mapping. The caller must ensure:
- The handle is valid and has appropriate permissions
- The offset and length are valid for the file
- The mapping will not be used after the OwnedReadWriteMmap is dropped
- Concurrent writes to the same region of the file may result in undefined behavior
Sourcepub unsafe fn from_handle(
handle: ReadWriteFileHandle,
offset: u64,
length: usize,
) -> Result<Self, MmapError>
pub unsafe fn from_handle( handle: ReadWriteFileHandle, offset: u64, length: usize, ) -> Result<Self, MmapError>
Creates a new owned memory mapping from a file handle, automatically wrapping it in an Arc.
This is a convenience constructor that takes ownership of a ReadWriteFileHandle and wraps it in an Arc.
§Arguments
handle
- The file handle to mapoffset
- The offset into the file to start the mappinglength
- The length of the mapping
§Safety
Same safety requirements as new()
.
Methods from Deref<Target = ReadWriteMmap<'static>>§
Sourcepub fn as_slice(&self) -> &'a [u8] ⓘ
pub fn as_slice(&self) -> &'a [u8] ⓘ
Returns a slice of the mapped memory. The lifetime of the slice is the same as the mapping.
Sourcepub fn as_mut_slice(&mut self) -> &'a mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &'a mut [u8] ⓘ
Returns a mutable slice of the mapped memory. The lifetime of the slice is the same as the mapping.
Sourcepub fn data(&self) -> *mut u8
pub fn data(&self) -> *mut u8
Returns a raw pointer to the mapped memory.
The returned pointer is adjusted for the requested offset, accounting for any page alignment requirements.
§Safety
The caller must ensure that the memory is accessed within the bounds of
the mapping. The caller must also ensure the pointer does not outlast the
lifetime of the mapping. It is recommended you use Self::as_slice
or
Self::as_mut_slice
instead for compiler enforced safety.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the mapped region in bytes.
This returns the originally requested length, not including any padding added for page alignment.
Sourcepub fn advise(&self, advice: MemoryAdvice)
pub fn advise(&self, advice: MemoryAdvice)
Provides advice to the operating system about how the memory mapping will be accessed.
§Arguments
advice
- Bit flags indicating the expected access patterns for this memory region
§Note
This is a hint to the operating system and may be ignored. Not all advice types
are supported on all platforms. On Windows, only MemoryAdvice::WILL_NEED
has an effect.
Multiple advice flags can be combined using bitwise operations.