pub struct AlignedRegion { /* private fields */ }Expand description
A page-aligned heap region. The buffer pool owns exactly one of these, which satisfies the alignment requirement of unbuffered I/O and the “allocate once, never free” requirement that keeps allocator retention out of the picture.
Implementations§
Source§impl AlignedRegion
impl AlignedRegion
pub fn new(len: usize) -> Result<Self>
Sourcepub unsafe fn page(&self, i: usize) -> &[u8] ⓘ
pub unsafe fn page(&self, i: usize) -> &[u8] ⓘ
§Safety
No &mut to frame i may be live for the lifetime of the returned
slice. The buffer pool guarantees this with its pin count; this type
cannot.
Sourcepub unsafe fn page_mut(&self, i: usize) -> &mut [u8] ⓘ
pub unsafe fn page_mut(&self, i: usize) -> &mut [u8] ⓘ
§Safety
No other reference to frame i — shared or mutable — may be live for
the lifetime of the returned slice.
This is deliberately an unsafe fn. As a safe fn, ordinary safe code
could call it twice and hold two &mut [u8] over the same bytes, which
is undefined behaviour however careful the pool is. A comment cannot
make an unenforceable invariant sound; moving the obligation to the
caller, in the type system, can.