J
Jack Boot
hi
we have been discussing methods for multidimensional heap arrays, between
us we have 3 preferred approaches
1: array of pointers each mallocated, ie
int ** A = malloc(nrow * sizeof(int*));
for(i=0;i<nrow;i++) A=malloc(ncol * sizeof(int));
2: array of pointers set into one big mallocated array, ie
int ** A = malloc(nrow * sizeof(int*));
int * Astorage = malloc(nrow * ncol * sizeof(int));
for(i=0;i<nrow;i++) A=Astorage+i*ncol;
3: one big mallocated array, no separate row pointers but an accessor
macro instead, ie
int * Astorage = malloc(nrow * ncol * sizeof(int));
#define A(i,j) Astorage[i*ncol+j];
what is your opinion of these methods? what situations is one is better
than another? should some of them never be used? what is standard/best
practice?
cheers
JB
we have been discussing methods for multidimensional heap arrays, between
us we have 3 preferred approaches
1: array of pointers each mallocated, ie
int ** A = malloc(nrow * sizeof(int*));
for(i=0;i<nrow;i++) A=malloc(ncol * sizeof(int));
2: array of pointers set into one big mallocated array, ie
int ** A = malloc(nrow * sizeof(int*));
int * Astorage = malloc(nrow * ncol * sizeof(int));
for(i=0;i<nrow;i++) A=Astorage+i*ncol;
3: one big mallocated array, no separate row pointers but an accessor
macro instead, ie
int * Astorage = malloc(nrow * ncol * sizeof(int));
#define A(i,j) Astorage[i*ncol+j];
what is your opinion of these methods? what situations is one is better
than another? should some of them never be used? what is standard/best
practice?
cheers
JB