Crate mmap_buffer

source ·
Expand description

mmap-backed provides a (mostly) safe buffer which is backed by a file using an mmap system call. These buffers don’t support dynamic reallocation, so they are fixed size. Here is an example:

use mmap_buffer::BackedBuffer;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    {
        let mut buf = BackedBuffer::<i32>::new(100, "test.data")?;

        // These changes will be reflected in the file
        buf[10] = -10;
        buf[20] = 27;
    }
     
    // Later, we can load the same array
    let mut buf = BackedBuffer::<i32>::load("test.data")?;

    assert_eq!(buf[10], -10);
    assert_eq!(buf[20], 27);

    Ok(())
}

Structs

  • A fixed size, mutable buffer of T backed by a file. In order to avoid copying when reading and writing from such a buffer, we require that T: Pod.

Enums

  • Helpful abstraction for some buffer, either backed by a file, or stored in memory