Hi there,

I need to make thousands of access to matrix elements in an algorithm that usually spend hours running. So, I want to implement this as much optimized as I can.

Then, supose I implement the matrix M by N using a vector.

long double *Matrix;

// alloc memory as a vector.

In this case I would access an element (i,j) like this:

long double Element = *(Matrix + (i-1)*N + j - 1);

Now, supose I implement the same matrix M by N as:

long double **Matrix;

// alloc memory as a matrix.

In this case I would access an element (i,j) using:

long double Element = *( *(Matrix + (i-1)) + j - 1);

The “-1” is because my matrixs are not zero-based ( of course you know that )

So, which one you think it would be faster? (Remember it is done thousands of times)

If you know assembly and compilers or have a point about that, please let me know.

Thanks