#mmap #file #memory-mapped #memory-mapping #read-write #api #append

mmap-simple

Write, read, append and delete from an mmapped file with a very simple API

3 unstable releases

0.2.0 May 16, 2024
0.1.1 May 14, 2024
0.1.0 May 13, 2024

#638 in Unix APIs

Download history 2/week @ 2024-09-17 23/week @ 2024-09-24

99 downloads per month

MIT license

16KB
204 lines

mmap-simple

docs.rs crates.io

mmap-simple is a Rust crate for simple yet fast memory-mapping of files, providing simple APIs for writing, appending, reading and dropping from the file.

Getting Started

To use mmap-simple, add it to your Cargo.toml under [dependencies]:

[dependencies]
mmap-simple= "0.1.0"

Read the docs for a little bit of more info.


lib.rs:

A simple API for treating a file basically as an infinite vector that can be written to at any point, appended to, read from and shrinken at will and in a very fast way.

The file is memory-mapped with a libc call specifying basically an infinite memory size. But it doesn't consume that amount of memory. Should only be used on Linux and from a single caller/process. All write calls immediately call sync_all after them, which is not ideal, but maybe we'll improve later.

Example

use std::path::Path;
use mmap_simple::Mmap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut mmap = Mmap::new(Path::new("example.txt"))?;
    mmap.append(b"Hello, world!")?;
    mmap.overwrite(0, b"Goodbye")?;
    mmap.drop_from_tail(6)?;
    mmap.append(b", world!")?;
    Ok(())
}

Dependencies

~43KB