Unlike initializing state variables in specific orders in order to save on gas, does this also apply to how you declare your struct properties where you keep lower uint
s side by side each other?
// State arranged to save gas
contract Foobar {
uint8 foo;
uint8 bar;
uint16 baz;
uint num;
}
// Does the same concept apply to a struct as well?
struct Item {
uint8 foo;
uint8 bar;
uint16 baz;
uint num;
}
Or can you go all crazy in the struct and type it in any order?
Best Answer
If you are refering to struct stored in
storage
then yes, the very same rules apply as described in the documentation :In memory however, every element is stored on 32 bytes, except for
bytes
andstring
as you can see here.