#size #cache #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

#12 in #three

Download history 208/week @ 2024-10-23 264/week @ 2024-10-30 305/week @ 2024-11-06 212/week @ 2024-11-13 286/week @ 2024-11-20 165/week @ 2024-11-27 316/week @ 2024-12-04 229/week @ 2024-12-11 109/week @ 2024-12-18 21/week @ 2024-12-25 180/week @ 2025-01-01 261/week @ 2025-01-08 325/week @ 2025-01-15 311/week @ 2025-01-22 125/week @ 2025-01-29 454/week @ 2025-02-05

1,278 downloads per month
Used in 5 crates (4 directly)

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