Skip to content

Virtual memory backed circular buffer implementation in rust

License

Notifications You must be signed in to change notification settings

mmaroti/vmcircbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vmcircbuf

Build Status Crate Documentation GitHub

This is a simple crate to create a circular buffer that magically wraps around without any copying. The buffer holds exactly size many bytes but it is presented as a size + wrap length slice where the last wrap many bytes overlap with the first wrap many bytes of the slice. This magic trick is performed with virtual memory, the same physical pages are mapped both at the start and at the end of the buffer. This crate is working on Linux, OSX, Windows, iOS, Android, Raspberry PI and MIPS.

let mut buffer = Buffer::new(1024, 100).unwrap();
let size = buffer.size();
let wrap = buffer.wrap();
assert!(size >= 1024 && wrap >= 100);
let slice: &mut [u8] = buffer.as_mut_slice();
assert_eq!(slice.len(), size + wrap);

for a in slice.iter_mut() {
    *a = 0;
}

slice[0] = 123;
assert_eq!(slice[size], 123);

About

Virtual memory backed circular buffer implementation in rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages