| ▲ | porise 17 hours ago | |
Why is rust allowed to reorder fields? If I know that fields are going to be generally accessed together, this prevents me from ordering them so they fit in cache lines. | ||
| ▲ | tialaramex 15 hours ago | parent | next [-] | |
You can choose in Rust to explain the representation you want for your data type. Unlike C or C++ that's not a non-portable vendor extension it's just part of the language, look at the repr documentation: https://doc.rust-lang.org/nomicon/other-reprs.html So if you want "what C does" you can just repr(C) and that's what you get. For most people that's not a good trade unless they're doing FFI with a language that shares this representational choice. | ||
| ▲ | kzrdude 17 hours ago | parent | prev | next [-] | |
It's allowed as an optimization, the order it uses will limit the space lost to field alignment. | ||
| ▲ | Narishma 17 hours ago | parent | prev [-] | |
You can tell it not to reorder them if you want but it's not the default. | ||