pub struct VirtualRange { /* private fields */ }Expand description
A reserved range of virtual addresses with nothing behind it yet.
Reserving costs address space, not memory. Blocks are mapped in afterwards
with VirtualRange::map, and the range is readable only where something
has been mapped — touching an unmapped offset faults rather than reading
zeroes, which is deliberate: a silent zero would look like KV that was
written but empty.
Implementations§
Source§impl VirtualRange
impl VirtualRange
Sourcepub fn reserve(len: usize) -> Result<Self, VirtualMemoryError>
pub fn reserve(len: usize) -> Result<Self, VirtualMemoryError>
Reserve len bytes of address space.
len must be a multiple of granularity.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the reservation covers no bytes.
Always false: a zero-length reservation is refused at construction.
Sourcepub fn mapped_bytes(&self) -> usize
pub fn mapped_bytes(&self) -> usize
Bytes currently backed by a mapped block.
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
The base address. Only offsets that have been mapped may be read.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
The base address, mutable.
Sourcepub fn map(
&mut self,
offset: usize,
len: usize,
) -> Result<(), VirtualMemoryError>
pub fn map( &mut self, offset: usize, len: usize, ) -> Result<(), VirtualMemoryError>
Back offset..offset + len with freshly committed memory.
Both offset and len must be multiples of granularity.
Sourcepub fn unmap(&mut self, offset: usize) -> Result<(), VirtualMemoryError>
pub fn unmap(&mut self, offset: usize) -> Result<(), VirtualMemoryError>
Release the block backing offset, leaving the address space reserved.
The offset must be one previously passed to Self::map; releasing a
sub-range would strand the remainder of the block.