#[repr(align(64))]pub struct AlignedBuffer64<T, const N: usize>{ /* private fields */ }Expand description
64-byte aligned buffer for cache line optimization and false sharing prevention
Aligns data structures to CPU cache line boundaries (typically 64 bytes) to maximize cache efficiency and prevent false sharing in multi-threaded HFT applications.
§Cache Line Benefits
- Cache efficiency: Entire buffer fits within cache line boundaries
- False sharing prevention: Eliminates cache ping-ponging between cores
- Memory bandwidth: Maximizes utilization of cache line transfers
- Prefetching optimization: Predictable access patterns improve prefetcher efficiency
§HFT Use Cases
- Per-thread buffers: Eliminate false sharing between trading threads
- Order book snapshots: Cache-efficient storage of market data
- Statistics collections: High-frequency counter updates
- Message buffers: Network I/O optimization
Implementations§
Source§impl<T, const N: usize> AlignedBuffer64<T, N>
impl<T, const N: usize> AlignedBuffer64<T, N>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new 64-byte aligned buffer with all elements initialized to default
Sourcepub const fn with_value(value: T) -> Self
pub const fn with_value(value: T) -> Self
Create a new 64-byte aligned buffer with all elements initialized to the given value
Sourcepub const fn as_mut_slice(&mut self) -> &mut [T]
pub const fn as_mut_slice(&mut self) -> &mut [T]
Get a mutable slice view of the buffer data
Trait Implementations§
Auto Trait Implementations§
impl<T, const N: usize> Freeze for AlignedBuffer64<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for AlignedBuffer64<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for AlignedBuffer64<T, N>where
T: Send,
impl<T, const N: usize> Sync for AlignedBuffer64<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for AlignedBuffer64<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for AlignedBuffer64<T, N>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more