4/8 In C++, is there a better way of doing this?
double **dbl; // this line should not change.
dbl = new (double *)[SomeVar];
for (int i = 0; i < SomeVar; i++) {
dbl[i] = new double[SomeOtherVar];
}
\_ Yes:
double **dbl,*dbl_temp;
dbl = new (double *)[SomeVar];
dbl_temp = new double[SomeVar*SomeOtherVar];
for (int i = 0; i < SomeVar; i++)
dbl[i] = &dbl_temp[i*SomeOtherVar];
This should decrease OS overhead for repeated new/malloc
calls. -alexf [fu initially obtained from mconst]
\_ This is particularly useful on certain vector architectures
that support strided loads and stores. The arrangement of
data allows you to efficiently perform matrix multiplications
on either column major or row major matrices without having
to do successive merges and unpacks like AltiVec does.
But who do we care. None of us have vector processors at our
disposals.
\_ this is useful regardless. it lets you write matrix
multiplication using only one loop which increments the
matrix pointer by 1, and increments the vector pointer
by 1 modulo its length. your matrix multiplies will fly! -ali
\_ I just rented it. It was better on DVD.
\_ how do you mean? doesn't this just give you the diagonals
of the result?
\_ but the math will fly! all the way to the stars...
\_ Per Aspera ad Astra, motherfucker. |