Skip to main content

MemMapCfg

Struct MemMapCfg 

Source
pub struct MemMapCfg {
    pub module_id: u8,
    pub path: PathBuf,
    pub name: [u8; 4],
    pub version: u32,
    pub initial_pages: usize,
    pub max_len: usize,
    pub sync_interval: Option<Duration>,
    pub memory_priority_hint: bool,
    pub sequential_access_hint: bool,
}
Expand description

Configurations for MemMap

§Example

use frozen_core::memmap::MemMapCfg;
use std::time::Duration;

let dir = tempfile::tempdir().unwrap();
let cfg = MemMapCfg {
    module_id: 1,
    path: dir.path().to_path_buf(),
    name: *b"tbfx",
    version: 1,
    initial_pages: 1,
    max_len: 0x10_0000,
    sync_interval: Some(Duration::from_millis(0x64)),
    memory_priority_hint: false,
    sequential_access_hint: false,
};

assert_eq!(cfg.name, *b"tbfx");
assert_eq!(cfg.version, 1);
assert_eq!(cfg.initial_pages, 1);
assert_eq!(cfg.max_len, 0x10_0000);
assert_eq!(cfg.sync_interval, Some(Duration::from_millis(0x64)));

Fields§

§module_id: u8

Identifier used while error propagation

§path: PathBuf

Directory path hosting the backing file

§name: [u8; 4]

4-byte ASCII identifier tag

§version: u32

Schema or layout version of the underlying memory-mapped file

Because the binary layout on disk is constructed according to the initial type T and structural parameters, MemMap strictly requires type invariants across a file’s lifetime

When an application evolves its data structures or migrates T, incrementing version ensures a new versioned backing file (<name>_<ver>) is created on disk without corrupting or clashing with previously persisted data

§initial_pages: usize

Number of virtual memory pages to pre-allocate on fs when MemMap is initialized

Initial file length will be initial_pages * page_size (bytes)

§max_len: usize

Maximum virtual address space reservation in bytes

Defines the upper boundary of virtual memory reserved upfront for the memory mapping

Must be page-aligned and greater than or equal to initial_pages * page_size

§sync_interval: Option<Duration>

Optional interval for the background sync thread

If Some(duration), a background worker thread is spawned which flushes dirty mapped pages at this interval; and if None, background sync is disabled and durability advances via manual sync or forced tickets

§memory_priority_hint: bool

Optional hint to lower process memory priority on Windows to optimize page reclamation under memory pressure

When set to true, MemMap::new, MemMap::open, and MemMap::open_or_create invoke the hint on a best-effort basis during initialization

§sequential_access_hint: bool

Optional hint to optimize sequential access patterns across mapped memory

When set to true, the underlying file is opened with sequential access optimizations (FILE_FLAG_SEQUENTIAL_SCAN on Windows, POSIX_FADV_SEQUENTIAL on Linux), and MemMap::new, MemMap::open, and MemMap::grow invoke sequential access advice on a best-effort basis

Implementations§

Source§

impl MemMapCfg

Source

pub fn versioned_path(&self) -> PathBuf

Computes the versioned file path formatted as {dir}/{name}_{version}

Trait Implementations§

Source§

impl Clone for MemMapCfg

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemMapCfg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.