I think I don't quite understand what you mean about 2D+ arrays. Are they different in handling when resizing them up and down?
My intention was simply like the following:
Code: Select all
ArrayInit(bar, 0, 1); //"small declaration"
ArrayInit(foo, 0, 1); //"small declaration"
//upsizing array1 when mem space is needed (e.g., astar calculations)
ArrayInit(bar, 0, imax);
//... do something
// downsizing when intermediate calculations are done
ArrayInit(bar, 0, 1);
//upsizing array2 when mem space is needed (e.g., bug2 calculations)
ArrayInit(foo, 0, jmax);
//... do something
// downsizing when intermediate calculations are done to free all memory again
ArrayInit(foo, 0, 1);
with multi-dim arrays (2D, maybe 3D) I would do it similarily. Would that be right or wrong?
according to the TO question a 2D size changing macro could be the following (works with all (either) different array types):
Code: Select all
#define ArrayInit2D(bar, tmp, init_val, dimx, dimy) { \
ArrayInit(tmp, init_val, dimy); \
ArrayInit(bar, tmp, dimx); \
}
use:
declare the 2D-array variable type (int/long/char/float/double), ;)
declare a 1D-tmp array of same type
use ArrayInit2D with array, temp, init_value, and array (x,y) dimensions
Code: Select all
int myArray[][], tmpArray[];
ArrayInit2D(myArray, tmpArray, 111, 10, 20);
// creates a 10x20 array of integer and initializes it with 111
ArrayInit2D(myArray, tmpArray, 111, 1, 1); // resizes myArray and tempArray to the minimum dim [1]
ArrayInit2D(myArray, tmpArray, -1, 15, 30); // upsizes myArray to 15x30 initialized with -1