Consider this value object Myclass
which has following members.
There would be hundred-thousands of MyClass
instances.
Optional fields would have about 50% population.
All optional would either be populated or they will not.
which is more efficient for memory?
1.
class MyClass{
String mandatory1;
int mandatory2;
double mandatory3;
String optional1;
int optional2;
double optional3;
//lets say there are 10+ like these
}
2. Wrap optional fields in a DS and set it as null when optional value are not present.
class MyClass{
String mandatory1;
int mandatory2;
double mandatory3;
OptionalParams params;
}
Question - Does wrapping up in DS wont set the null references for the members within ? So effectively one null reference vs 10+ null references ?
I understand that with null values it doesn't matter much but i do care about the memory used by references ?