Struct scratchpad::CacheAligned[][src]

#[repr(C, align(64))]pub struct CacheAligned(pub [u8; 64]);

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));

Trait Implementations

impl ByteData for CacheAligned[src]

impl Clone for CacheAligned[src]

impl Copy for CacheAligned[src]

impl Debug for CacheAligned[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.