Hi! I was writing some code for a file parser, and then I noticed something really weird, I was checking to the size of the structure be equal to the structure we will use, for this I use std::mem::size_of
, but after change some part of the structure, which should have the same size (change two u32 for one u64), the first one has a size of 252 bytes, and after change to u64 changes to 256................
I try reduce most I can the code, but any change from here causes to hide this.
Is for a game, you will notice by the fields
pub struct ItemModel {
pub r#type: u32,
pub id: u32,
pub name_offset: u32,
pub unknown_01: [u16; 59],
pub unknown_03: u32,
pub unknown_04: u32,
pub unknown_05: u32,
pub unknown_06: u32,
pub unknown_07: u32,
pub unknown_08: u32,
pub chara_user: u32,
pub unknown_02: u32,
pub type_item: u16,
pub max_count: u16,
pub buy_price: u32,
pub sell_price: u32,
pub stats: Stats,
pub unknown_44: [u16; 10],
pub chip_level: u16,
pub ability: u16,
pub desc_offset: u32,
}
pub struct Stats {
pub hit_points: i32,
pub unknown_01: i32,
pub skill_points: i32,
pub strength: i32,
pub vitality: i32,
pub intelligence: i32,
pub mentality: i32,
pub agility: i32,
pub technique: i32,
pub unknown_02: i32,
pub luck: i32,
pub movement: i32,
}
fn main() {
println!("Item1 {}", std::mem::size_of::<ItemModel>());
}
Run the code, the output will be 252.
Change:
pub unknown_03: u32,
pub unknown_04: u32,
To:
pub unknown_03: u64,
Run again the code, and magically, the size now is 256! I tested this on the RustPlayground... no idea why this happens....
Thx!