12 releases

0.0.12 Dec 13, 2025
0.0.11 Nov 14, 2025
0.0.10 Sep 1, 2023
0.0.9 Jun 6, 2022
0.0.5 Sep 24, 2021

#649 in Asynchronous

Download history 117/week @ 2025-10-19 24/week @ 2025-10-26 134/week @ 2025-11-02 63/week @ 2025-11-09 44/week @ 2025-11-16 66/week @ 2025-11-23 41/week @ 2025-11-30 93/week @ 2025-12-07 116/week @ 2025-12-14 28/week @ 2025-12-21 13/week @ 2025-12-28 49/week @ 2026-01-04 20/week @ 2026-01-11 80/week @ 2026-01-18 47/week @ 2026-01-25 35/week @ 2026-02-01

182 downloads per month
Used in 5 crates (2 directly)

Apache-2.0

48KB
937 lines

Double Mapped Circular Buffer

  • Thread-safe.
  • Supports multiple readers.
  • Generic over the item type.
  • Provides access to all items (not n-1).
  • Supports Linux, macOS, Windows, and Android.
  • Sync, async, and non-blocking implementations.
  • Generic variant that allows specifying custom Notifiers to ease integration.
  • Underlying data structure (i.e., DoubleMappedBuffer) is exported to allow custom implementations.

Crates.io Apache 2.0 licensed Build Status

Overview

This circular buffer implementation maps the underlying buffer twice, back-to-back into the virtual address space of the process. This arrangement allows the circular buffer to present the available data sequentially, (i.e., as a slice) without having to worry about wrapping.

Example

use vmcircbuffer::sync;

let mut w = sync::Circular::new::<u32>()?;
let mut r = w.add_reader();

// delay producing by 1 sec
let now = std::time::Instant::now();
let delay = std::time::Duration::from_millis(1000);

// producer thread
std::thread::spawn(move || {
    std::thread::sleep(delay);
    let w_buff = w.slice();
    for v in w_buff.iter_mut() {
        *v = 23;
    }
    let l = w_buff.len();
    w.produce(l);
});

// blocks until data becomes available
let r_buff = r.slice().unwrap();
assert!(now.elapsed() > delay);
for v in r_buff {
    assert_eq!(*v, 23);
}
let l = r_buff.len();
r.consume(l);

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the project, shall be licensed as Apache 2.0, without any additional terms or conditions.

Dependencies

~0.4–1.2MB
~21K SLoC