How to optimize pointer layers

I am trying to optimize such things in a heavy computer application:

Let's say i have

 double d[500][500][500][500];

and the following, at least from the point of view of the compiler, is quite expensive

double d[x][y][j][k]

I want to say that the compiler is continuous memory in order to facilitate the offset calculation.

In my example

I have something like this:

double n=0;
for (int i=0; i < someNumber; i++)
{
    n+=d[x][i][j][k] /*(some other math calculations)*/;
}

So I tried to optimize it by putting it in a separate function

void func( double*** const restrict dMatrix )
{
  /* and do some calculations herel*/

}

did not help: (

Any suggestions for optimizing it?

}

Edit

I cannot rewrite the code to make the array one-dimensional. I need to work with this multi-dimensional beast :(

+3
source share
7 answers

, , . 4- , , , .

+14

, ( 466 , ), . 500 ^ 4, , , "", , .

+5

C , . .

+5

, , . , ( ), -, . CI , , , : . .

+4

C. 1-, . , , . C.

, , . a[0][?][?][?], , a[1][?][?][?].

+3

, , , , .

, .

char aString[500];
for (int i=0; i<500; i++)
    aString[i] = 0;     // Array access is really a multiply!

char aString[500];
char *aStringPtr;
for (aStringPtr= &aString[0] ; aStringPtr<&aString[0]+500; aStringPtr++)
    *aStringPtr = 0;

, .

+1

, . , . , , . , , . .

, . , .

, , , .

, , 64- . 32- 4 GB.

+1
source

Source: https://habr.com/ru/post/1717345/


All Articles