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: u8Identifier used while error propagation
path: PathBufDirectory path hosting the backing file
name: [u8; 4]4-byte ASCII identifier tag
version: u32Schema 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: usizeNumber 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: usizeMaximum 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: boolOptional 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: boolOptional 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