T
Tan Thuan Seah
Hi all,
I was told this in one of the university course I was doing.
In C we may expect good performance for:
double a[N][N], c[N][N], d;
for (i=0; i<N; i++)
for(j=0; j<N; j++)
a[j] = a[j] + c[j] *d;
But this is another matter:
double *a[N], *c[N], d;
for(i=0; i<N; i++) {a = (double *) malloc(N*sizeof(double));
c = (double *) malloc(N*sizeof(double)); }
for(i=0; i<N; i++)
for(j=0; j<N; j++)
a[j] = a[j] + c[j] * d;
It seems that we would expect some performance hit if we were to use dynamic
memory allocation of some sort. But it's not a standard ANSI C++ to have
array with the size determined during runtime. So is there any good
recommendation to minimize this performance hit or totally avoiding it
through some other method? I would expect a linked list to be even worse.
Any recommendation? Thanks.
Thuan Seah
I was told this in one of the university course I was doing.
In C we may expect good performance for:
double a[N][N], c[N][N], d;
for (i=0; i<N; i++)
for(j=0; j<N; j++)
a[j] = a[j] + c[j] *d;
But this is another matter:
double *a[N], *c[N], d;
for(i=0; i<N; i++) {a = (double *) malloc(N*sizeof(double));
c = (double *) malloc(N*sizeof(double)); }
for(i=0; i<N; i++)
for(j=0; j<N; j++)
a[j] = a[j] + c[j] * d;
It seems that we would expect some performance hit if we were to use dynamic
memory allocation of some sort. But it's not a standard ANSI C++ to have
array with the size determined during runtime. So is there any good
recommendation to minimize this performance hit or totally avoiding it
through some other method? I would expect a linked list to be even worse.
Any recommendation? Thanks.
Thuan Seah