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

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -