Struct CacheAligned

Source
#[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

Source§

fn clone(&self) -> CacheAligned

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CacheAligned

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ByteData for CacheAligned

Source§

impl Copy for CacheAligned

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoMutSliceLikePtr<[T]> for T

Source§

fn into_mut_slice_like_ptr(ptr: *mut T) -> *mut [T]

Reinterprets a mutable pointer of this type as a SliceLike pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.