Skip to main content

MemoryAccess

Trait MemoryAccess 

Source
pub trait MemoryAccess {
    // Required methods
    fn page_size(&self) -> u64;
    fn grow_one_page(&mut self) -> MemoryResult<Page>;
    fn zero_page(&mut self, page: Page) -> MemoryResult<()>;
    fn read_at<D>(&mut self, page: Page, offset: PageOffset) -> MemoryResult<D>
       where D: Encode;
    fn write_at<E>(
        &mut self,
        page: Page,
        offset: PageOffset,
        data: &E,
    ) -> MemoryResult<()>
       where E: Encode;
    fn write_at_raw(
        &mut self,
        page: Page,
        offset: PageOffset,
        buf: &[u8],
    ) -> MemoryResult<()>;
    fn zero<E>(
        &mut self,
        page: Page,
        offset: PageOffset,
        data: &E,
    ) -> MemoryResult<()>
       where E: Encode;
    fn zero_raw(
        &mut self,
        page: Page,
        offset: PageOffset,
        len: PageOffset,
    ) -> MemoryResult<()>;
    fn read_at_raw(
        &mut self,
        page: Page,
        offset: PageOffset,
        buf: &mut [u8],
    ) -> MemoryResult<usize>;

    // Provided methods
    fn claim_page(&mut self) -> MemoryResult<Page> { ... }
    fn unclaim_page(&mut self, page: Page) -> MemoryResult<()> { ... }
}
Expand description

Abstraction over page-level memory operations.

All table-registry and ledger functions are generic over this trait so that callers can transparently add write-ahead journaling or other interceptors without modifying the memory crate.

Required Methods§

Source

fn page_size(&self) -> u64

Returns the size of a single memory page.

Source

fn grow_one_page(&mut self) -> MemoryResult<Page>

Grows the underlying memory by exactly one page and returns the freshly allocated page number.

The returned page is zero-initialized. This primitive is not journaled — page growth cannot be rolled back, so a transaction that aborts after a grow_one_page simply leaks the new page.

Source

fn zero_page(&mut self, page: Page) -> MemoryResult<()>

Zeros out an entire page. Used by MemoryAccess::unclaim_page to scrub residual data before publishing the page to the unclaimed-pages ledger.

Source

fn read_at<D>(&mut self, page: Page, offset: PageOffset) -> MemoryResult<D>
where D: Encode,

Reads a typed value from the specified page and offset.

Source

fn write_at<E>( &mut self, page: Page, offset: PageOffset, data: &E, ) -> MemoryResult<()>
where E: Encode,

Writes a typed value at the specified page and offset.

Source

fn write_at_raw( &mut self, page: Page, offset: PageOffset, buf: &[u8], ) -> MemoryResult<()>

Writes raw bytes at the specified page and offset, bypassing alignment and encoding checks.

Source

fn zero<E>( &mut self, page: Page, offset: PageOffset, data: &E, ) -> MemoryResult<()>
where E: Encode,

Zeros out the region occupied by data at the specified page and offset.

Source

fn zero_raw( &mut self, page: Page, offset: PageOffset, len: PageOffset, ) -> MemoryResult<()>

Zeros out len raw bytes at the specified page and offset.

Used by the migration apply pipeline when scrubbing a record whose size is known only at runtime (from a stored snapshot).

Source

fn read_at_raw( &mut self, page: Page, offset: PageOffset, buf: &mut [u8], ) -> MemoryResult<usize>

Reads raw bytes into buf at the specified page and offset.

Returns the number of bytes actually read.

Provided Methods§

Source

fn claim_page(&mut self) -> MemoryResult<Page>

Hands out a page for use by a caller.

Reuses a page from the unclaimed-pages ledger when one is available; otherwise grows the memory by one page.

Source

fn unclaim_page(&mut self, page: Page) -> MemoryResult<()>

Returns page to the unclaimed-pages ledger so it can be reused by a future MemoryAccess::claim_page call.

The page contents are zeroed before being published to the ledger.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§