Skip to content

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

License

Notifications You must be signed in to change notification settings

tinco/cache_line_size

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages