pub struct Buffer { /* private fields */ }Expand description
A 4 KB-aligned, heap-allocated byte buffer suitable for O_DIRECT I/O.
Buffer owns a single contiguous allocation that is aligned to a
FOUR_KB_BLOCK (4 096 bytes) — the minimum alignment required by
O_DIRECT on all common block devices.
Cursor management is not handled here. Instead, FlushBuffer uses
atomic fetch-and-add on its packed state word to hand out non-overlapping
byte ranges to concurrent writers. This is what makes the
unsafe impl Sync sound: no two threads are ever granted the same region.
§Safety
Sync is manually implemented because UnsafeCell opts out of it by
default. The invariant that upholds this is: all mutable access to the
inner pointer is mediated by FlushBuffer, which guarantees exclusive
ranges per writer.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new_aligned(size: usize) -> Self
pub fn new_aligned(size: usize) -> Self
Allocate a zeroed, FOUR_KB_BLOCK-aligned buffer of size bytes.
§Panics
Panics if size is not a multiple of FOUR_KB_BLOCK, if the layout
is otherwise invalid, or if the allocator returns a null pointer.