So, this is probably a bit abstract, and I apologize if the title was imprecise:
I have a simulation class, which contains a vector of objects of class A, the member functions of which depend on parameters a,b,c:
class SIMULATION
{
vector<A> array;
};
class A
{
A(a,b,c);
}
Within each SIMULATION, a, b and c are constant. Therefore it seems to be a bad idea to give each A its own copies of a, b, c - I only need one for each SIMULATION.
What I do right now is make a, b, c static members of A. That takes care of the memory "problem". However, making the variables belong to A is a bit of an issue, since if my code contains multiple SIMULATIONs, one will indirectly change the parameters in another. That seems a recipe for confounding errors. Then I have considered making a, b, c members of SIMULATION. This is safe, and makes sense. However, as I see it, that would require A to dereference a pointer each time it needs to do something (to access the variables). That is not quite satisfactory either, since speed is really important in this problem (I will be using a, b, c hundreds of millions of times each).
do you have any suggestions as to how I might make A access values of a, b, c (for speed) and still have good separation of the different SIMULATIONs?
Should I expect a speed-increase if I changed a, b, c from static to "local"? (in which case I might ignore the ugliness of having 10 000 identical values). it is my impression that keeping stuff that is used together close together in memory is a good trick.
wise comments, or really good jokes, will be appreciated =)