atomic-rs
atomic-rs copied to clipboard
Why compare `align_of`?
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Test {
a: u8,
b: u8,
c: u8,
d: u8,
}
fn main() {
println!("align: {}", core::mem::align_of::<Test>());
println!("size: {}", core::mem::size_of::<Test>());
}
Size of the struct is 4
, align of the struct is 1
.
The condition is not met.
I think Atomic<Test >
can be converted to AtomicU32
You can use #[repr(align(4))]
on your struct to ensure the alignment is sufficient. This is required since this crate will unsafely access your struct as an AtomicU32
.
transmute
don't require alignment, how about replace transmute_copy
by transmute
?
This crate isn't actually transmuting though, it's casting a pointer to your type to a pointer to AtomicU32
and accessing it as an AtomicU32
in-place. This requires that your type be suitably aligned for an AtomicU32
.