I have a design choice to make: Do I create an array of wrapper objects each containing a few distinct values, or do I create an object that contains a few distinct arrays of values?
Option 1:
Node[][] nodes;
class Node{
double val1;
double val2;
}
Option 2:
Node[] nodes;
class Node{
double[] val1;
double[] val2;
}
My gut says that option 2 would be more efficient only because there would be fewer objects and thus less overhead, but would the double[]'s be just as expensive?
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil- Donald KnuthInterfacefor your array and have your arrays implement it, that way if for some reason one array does not meet your requirements you'll easily be able to sub it for the other.