#cache #size #line

cache_line_size

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

3 releases (1 stable)

✓ Uses Rust 2018 edition

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

#53 in Caching

Download history 10/week @ 2018-10-17 2/week @ 2018-10-24 27/week @ 2018-10-31 10/week @ 2018-11-07 12/week @ 2018-11-14 6/week @ 2018-11-21 33/week @ 2018-11-28 5/week @ 2018-12-05 9/week @ 2018-12-12 16/week @ 2018-12-19 2/week @ 2018-12-26 3/week @ 2019-01-02 6/week @ 2019-01-09 4/week @ 2019-01-16 6/week @ 2019-01-23

19 downloads per month
Used in 1 crate

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