rust - Why does an enum require extra memory size? -
my understanding enum
union
in c , system allocate largest of data types in enum.
enum e1 { dblval1(f64), } enum e2 { dblval1(f64), dblval2(f64), dblval3(f64), dblval4(f64), } fn main() { println!("size {}", std::mem::size_of::<e1>()); println!("size {}", std::mem::size_of::<e2>()); }
why e1
takes 8 bytes expected, e2
takes 16 bytes?
in rust, unlike in c, enum
s tagged unions. is, enum
knows value holds. 8 bytes wouldn't enough because there no room tag.
Comments
Post a Comment