[−][src]Struct vmap::AllocSize
Type for calculation page size information.
Example
let size = vmap::AllocSize::new(); let pages = size.count(200); assert_eq!(pages, 1); let round = size.round(200); println!("200 bytes requires a {} byte mapping", round); let count = size.count(10000); println!("10000 bytes requires {} pages", count); let size = size.size(3); println!("3 pages are {} bytes", size);
Methods
impl AllocSize
[src]
pub fn new() -> Self
[src]
Creates a type for calculating page numbers and byte offsets.
The size is determined from the system's configurated page size. This value is cached making it very cheap to construct.
pub unsafe fn with_size(size: usize) -> Self
[src]
Creates a type for calculating page numbers and byte offsets using a known page size.
Safety
The size must be a power-of-2. To successfully map pages, the size must also be a mutliple of the actual system page size. Hypothetically this could be used to simulate larger page sizes.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = unsafe { AllocSize::with_size(sys << 2) }; assert_eq!(size.round(1), sys << 2); // probably 16384
pub fn round(&self, len: usize) -> usize
[src]
Round a byte size up to the nearest page size.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = AllocSize::new(); assert_eq!(size.round(0), 0); assert_eq!(size.round(1), sys); // probably 4096 assert_eq!(size.round(sys-1), sys); // probably 4096 assert_eq!(size.round(sys), sys); // probably 4096 assert_eq!(size.round(sys+1), sys*2); // probably 8192
pub fn truncate(&self, len: usize) -> usize
[src]
Round a byte size down to the nearest page size.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = AllocSize::new(); assert_eq!(size.truncate(0), 0); assert_eq!(size.truncate(1), 0); assert_eq!(size.truncate(sys-1), 0); assert_eq!(size.truncate(sys), sys); // probably 4096 assert_eq!(size.truncate(sys+1), sys); // probably 4096
pub fn offset(&self, len: usize) -> usize
[src]
Calculate the byte offset from page containing the position.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = AllocSize::new(); assert_eq!(size.offset(1), 1); assert_eq!(size.offset(sys-1), sys-1); assert_eq!(size.offset(sys*2 + 123), 123);
pub fn size(&self, count: Pgno) -> usize
[src]
Convert a page count into a byte size.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = AllocSize::new(); assert_eq!(size.size(0), 0); assert_eq!(size.size(1), sys); // probably 4096 assert_eq!(size.size(2), sys*2); // probably 8192
pub fn count(&self, len: usize) -> Pgno
[src]
Covert a byte size into the number of pages necessary to contain it.
Example
use vmap::AllocSize; let sys = vmap::allocation_size(); let size = AllocSize::new(); assert_eq!(size.count(0), 0); assert_eq!(size.count(1), 1); assert_eq!(size.count(sys-1), 1); assert_eq!(size.count(sys), 1); assert_eq!(size.count(sys+1), 2); assert_eq!(size.count(sys*2), 2);
pub unsafe fn bounds(&self, ptr: *mut u8, len: usize) -> (*mut u8, usize)
[src]
Calculates the page bounds for a pointer and length.
Safety
There is no verification that the pointer is a mapped page nor that the calculated offset may be dereferenced.
Trait Implementations
impl Clone for AllocSize
[src]
fn clone(&self) -> AllocSize
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for AllocSize
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,