Hi all,
I have a setup where several functions use certain variables, which for that reason I've designated as globals.
Originally these were some pointers, let's call them,
Which were used by functions f1(), f2(), f3(), ...
The pointers are assigned to point to malloc'ed arrays of size N. However, it became necessary to have several different versions of these pointers so that the system described by x,y,z could be copied, modified, and the two or more systems run in parallel to see how they diverge, meaning I had to have more than one set of x,y,z pointers:
Of which, given any call to f1, f2, etc., the three that would be used would be either xA,yA,zA or xB,yB,zB, or xC,yC,zC.
The question is: is there any way to tell the functions f1(), f2(), ... which trio of pointers to use without actually passing the pointers [e.g f1(xA,yA,zA)], which is a waste of time since they're all globals?
One way would be to create a struct type containing x,y,z, and just pass a pointer to different structs, but I think that would slow down the processes inside of the functions.
Another way (overkill) would be to write out separate functions f1A(), f2A(), f3A(), f1B(), f2B(), f3B(), etc., but that seems like an unnecessary pain in the ass making it almost impossible to update the code effectively.
Is there a better way?
This is a serious number-crunching program so speed is of the essence---it's vital that any way of getting round the slow-down effect of passing lots of stuff not be offset by a slow-down elsewhere (which is why I rejected the struct option).
Any ideas?
Many thanks,
-- Joe
I have a setup where several functions use certain variables, which for that reason I've designated as globals.
Originally these were some pointers, let's call them,
Code:
int *x; double *y; int *z;
Which were used by functions f1(), f2(), f3(), ...
The pointers are assigned to point to malloc'ed arrays of size N. However, it became necessary to have several different versions of these pointers so that the system described by x,y,z could be copied, modified, and the two or more systems run in parallel to see how they diverge, meaning I had to have more than one set of x,y,z pointers:
Code:
int *xA, *xB, *xC;
double *yA, *yB, *yC;
int *zA, *zB, *zC;
Of which, given any call to f1, f2, etc., the three that would be used would be either xA,yA,zA or xB,yB,zB, or xC,yC,zC.
The question is: is there any way to tell the functions f1(), f2(), ... which trio of pointers to use without actually passing the pointers [e.g f1(xA,yA,zA)], which is a waste of time since they're all globals?
One way would be to create a struct type containing x,y,z, and just pass a pointer to different structs, but I think that would slow down the processes inside of the functions.
Another way (overkill) would be to write out separate functions f1A(), f2A(), f3A(), f1B(), f2B(), f3B(), etc., but that seems like an unnecessary pain in the ass making it almost impossible to update the code effectively.
Is there a better way?
This is a serious number-crunching program so speed is of the essence---it's vital that any way of getting round the slow-down effect of passing lots of stuff not be offset by a slow-down elsewhere (which is why I rejected the struct option).
Any ideas?
Many thanks,
-- Joe