I have a program that requires to create and delete a 2D array of variable size, hence the dynamic usage. However I wish to ask a simple question about the correct or recommended usage. For example, where should I reallocate the memory, should I simply free up the memory and use another allocation of memory i.e. memory allocation double etc should be done once...
or should be done in the loop
double **ptrBeadArrayOld = NULL;
ptrBeadArrayOld = (double **)malloc(BeadTotal * sizeof(double *));
for (i = 0; i< BeadTotal; i++)
free_2d(ptrBeadArrayOld);
or do I simply declare once?
double **ptrBeadArrayOld = NULL;
at the beginning of the program?? Thanks