Skip to main content

Module aligned

Module aligned 

Source
Expand description

Cache-line aligned types for high-performance operations.

Modern CPUs have 64-byte cache lines. Proper alignment prevents:

  • False sharing in concurrent code
  • Cache line splits during loads/stores
  • Suboptimal prefetching

§Usage

use moloch_core::aligned::{AlignedHash, AlignedHashArray};
use moloch_core::Hash;

// Single aligned hash (for hot paths)
let some_hash = Hash::ZERO;
let hash = AlignedHash::from(some_hash);

// Batch of aligned hashes (for SIMD operations)
let hashes = [Hash::ZERO; 4];
let mut batch = AlignedHashArray::<8>::default();
for (i, h) in hashes.iter().enumerate() {
    batch.set(i, *h);
}

Structs§

AlignedHash
A hash aligned to a cache line boundary.
AlignedHashArray
An array of hashes aligned to cache line boundaries.
CacheLinePadded
A cache-line padded wrapper to prevent false sharing.

Constants§

CACHE_LINE_SIZE
Cache line size on most modern CPUs (Intel, AMD, ARM).