#cache #size #line #architecture #expose #align #three

cache_line_size

A crate that exposes the size of a cache line on the current architecture

3 releases (1 stable)

1.0.0 Oct 14, 2018
0.2.0 Oct 13, 2018
0.1.0 Oct 13, 2018

#271 in Caching

Download history 46/week @ 2024-01-03 46/week @ 2024-01-10 23/week @ 2024-01-17 39/week @ 2024-01-24 23/week @ 2024-01-31 19/week @ 2024-02-07 73/week @ 2024-02-14 196/week @ 2024-02-21 285/week @ 2024-02-28 129/week @ 2024-03-06 146/week @ 2024-03-13 144/week @ 2024-03-20 178/week @ 2024-03-27 176/week @ 2024-04-03 98/week @ 2024-04-10 98/week @ 2024-04-17

580 downloads per month
Used in 2 crates

MIT license

4KB
59 lines

Cache Line Size

This is a crate that gives access to the cache line size of a given architecture. It also has a generic type that can be used to align its parameter to the cache line size.

For example, to have a struct with three u8 with each on its own cache line, you could write the following code:


use cache_line_size::{CacheAligned, CACHE_LINE_SIZE};
use std::mem::size_of;

struct ThreeLineStruct {
  line_1: CacheAligned<u8>,
  line_2: CacheAligned<u8>,
  line_3: CacheAligned<u8>,
}

#[test]
fn it_is_three_lines() {
    assert_eq!(size_of::<ThreeLineStruct>(), 3*CACHE_LINE_SIZE);
}

No runtime deps