Expand description
pre-allocated ring buffer storage.
the ring buffer is the core data structure for storing events in the channel. it uses a fixed-size circular array with power-of-2 capacity for efficient index calculations using bitwise AND instead of modulo.
§design
- pre-allocated slots to avoid allocation in hot path
- power-of-2 capacity for O(1) index calculation
- uses
UnsafeCell<MaybeUninit<T>>for interior mutability and uninitialized storage - zero-copy access via raw pointer operations
§safety
the ring buffer provides raw access methods that are unsafe. users must ensure:
- only one writer accesses a slot at a time
- readers only access slots that have been initialized
- proper synchronization between producers and consumers
§example
use scatto::ringbuffer::RingBuffer;
let buffer: RingBuffer<u64> = RingBuffer::new(1024);
assert_eq!(buffer.capacity(), 1024);
// write at sequence 0
unsafe {
buffer.write(0, 42);
assert_eq!(*buffer.get(0), 42);
}Structs§
- Ring
Buffer - pre-allocated ring buffer with runtime-configurable capacity.