farena 0.2.0

A file-backed arena allocator using pread for RSS-conscious byte storage
Documentation
farena-0.2.0 has been yanked.

farena

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

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 1

Buffer reuse

let mut buf = Vec::new();
arena.get_into(loc1, &mut buf)?;  // appends to buf

API

Method Description
FileArenaWriter::new() Create writer backed by temp file
writer.push(data) Append data, returns (offset, len)
writer.finish() Flush and return file handle
FileArena::new(files) Create arena from file handles
arena.get(loc) Read bytes at location
arena.get_into(loc, buf) Read bytes into buffer