Expand description
File-backed arena allocator using pread(2) for RSS-conscious byte storage.
§Usage
use farena::{FileArena, FileArenaWriter, Location};
// Write phase
let mut writer = FileArenaWriter::new()?;
let (offset1, len1) = writer.push("hello")?;
let (offset2, len2) = writer.push(" world")?;
let file = writer.finish()?.unwrap();
// Read phase
let arena = FileArena::new(vec![file])?;
let loc1 = Location::new(0, offset1, len1);
let loc2 = Location::new(0, offset2, len2);
assert_eq!(arena.get(loc1)?, b"hello");
assert_eq!(arena.get(loc2)?, b" world");§Multiple files
Each file gets an index in the arena:
let mut w1 = FileArenaWriter::new()?;
let (o1, l1) = w1.push("data1")?;
let f1 = w1.finish()?.unwrap();
let mut w2 = FileArenaWriter::new()?;
let (o2, l2) = w2.push("data2")?;
let f2 = w2.finish()?.unwrap();
let arena = FileArena::new(vec![f1, f2])?;
let loc1 = Location::new(0, o1, l1); // file index 0
let loc2 = Location::new(1, o2, l2); // file index 1Structs§
- File
Arena - Read-phase arena that retrieves stored data via
pread(2). - File
Arena Writer - A writer for appending data to an anonymous temp file.
- Location
- Metadata for locating a stored entry within a
crate::FileArena.