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, enums tagged unions. is, enum knows value holds. 8 bytes wouldn't enough because there no room tag.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -