Macro scratchpad::array_type_for_markers [] [src]

macro_rules! array_type_for_markers {
    ($element:ty, $marker_count:expr) => { ... };
    ($element:ty, $marker_count:expr,) => { ... };
}

Declares a static array of the specified element type that is large enough for storage of at least the specified number of allocation markers. The actual supported marker count may be larger due to padding.

Examples

#[macro_use]
extern crate scratchpad;

use scratchpad::{CacheAligned, Error, Scratchpad};

// `BufferType` is the same as `[CacheAligned; 1]` on targets using 32-bit
// pointers and `[CacheAligned; 2]` on targets using 64-bit pointers.
type BufferType = array_type_for_markers!(CacheAligned, 16);

#[cfg(target_pointer_width = "32")]
let buffer: BufferType = [CacheAligned([1; 64])];

#[cfg(target_pointer_width = "64")]
let buffer: BufferType = [CacheAligned([1; 64]), CacheAligned([2; 64])];

// Regardless of the target pointer size, the capacity of 16 markers is
// still the same.
let scratchpad = Scratchpad::new([0u64; 1], buffer);
let mut markers = Vec::new();
for _ in 0..16 {
    markers.push(scratchpad.mark_front().unwrap());
}

assert_eq!(scratchpad.mark_front().unwrap_err(), Error::MarkerLimit);