#[repr(C, align(64))]pub struct CacheAligned(pub [u8; 64]);
Expand description
Cache-aligned storage for Buffer
and Tracking
use.
Internally, this simply wraps a u8
array to ensure cache alignment.
Arrays and slices of this type can be used directly for either
Scratchpad
storage or marker tracking.
The alignment and size of CacheAligned
are determined by the
CACHE_ALIGNMENT
constant.
§Examples
use scratchpad::{CacheAligned, CACHE_ALIGNMENT, Scratchpad};
fn is_cache_aligned<T>(ptr: *const T) -> bool {
ptr as usize & (CACHE_ALIGNMENT - 1) == 0
}
// `CacheAligned` elements are guaranteed to always be aligned to
// `CACHE_ALIGNMENT` bytes, regardless of whether they're created on the
// stack, heap-allocated, or allocated from a `Scratchpad`.
let cache_aligned = cache_aligned_zeroed!();
assert!(is_cache_aligned(&cache_aligned));
let cache_aligned = Box::new(cache_aligned_zeroed!());
assert!(is_cache_aligned(&*cache_aligned));
let scratchpad = Scratchpad::new(
[cache_aligned_zeroed!(); 1],
[0usize; 1],
);
let marker = scratchpad.mark_front().expect("marker creation failed");
let cache_aligned = marker
.allocate(cache_aligned_zeroed!())
.expect("allocation failed");
assert!(is_cache_aligned(&*cache_aligned));
Tuple Fields§
§0: [u8; 64]
Trait Implementations§
Source§impl Clone for CacheAligned
impl Clone for CacheAligned
Source§fn clone(&self) -> CacheAligned
fn clone(&self) -> CacheAligned
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CacheAligned
impl Debug for CacheAligned
impl ByteData for CacheAligned
impl Copy for CacheAligned
Auto Trait Implementations§
impl Freeze for CacheAligned
impl RefUnwindSafe for CacheAligned
impl Send for CacheAligned
impl Sync for CacheAligned
impl Unpin for CacheAligned
impl UnwindSafe for CacheAligned
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