Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about changing my data structure

Author: Gerd Isenberg

Date: 15:33:11 07/17/03

Go up one level in this thread


>I understand now that i=A0[j] is faster than i=A[0][j]

No Uri, if A0 and A are static or global int arrays it should be the same.
Because the address A0 is known by the compiler, same for A[0].
A constant left most index doesn't matter.

But if A0 is a pointer array, there is an additional level of indirection *A.


>(I got the impression that
>it should be the same speed based on previous post)
>
>I do not understand exactly what you suggest.


I suggest, if you need a constant alias name for A[0]... to leave it to the
compiler or preprocessor - but not to blow up the code to derefere a pointer
every time via A0.


int  A [8][64]  ; the real array with  4 * 8 * 64 bytes
int* A0[8]      ; the alias array with 4 * 8 bytes (considering 32bit pointer)

May be your confusion in C is that A[0] is as pointer expression,
the address of A or A[0] or A[0][0], determined by compiler and linker.
A0[0] is a pointer. You may (or must) assign a value to the pointer before using
it.

A0[0] = someptr;
like
A0[0] = A[0];
but one more time
A[0] = someptr; // is invalid!!

Both objects (A,A0) are quite different objects with different size.
But you can use them in C with same syntax, same semantic but different
pragmatic:

 i = A[0][j];
 A[0][j]++;

or ( after some init like A0[0] = A[0]; assignment of pointer)

 i = A0[0][j]; // i = *(A0[0] + j);
 A0[0][j]++;   // *(A0[0] + j)

If you look to the assembler output in a small testprogram, you see the
difference.

Gerd

>
>In most cases I already use A0[j] or A3[j] and the only cases when I do not do
>it is when I want to use A[i][j] and i is not a constant number and in these
>cases I use the old array.
>
>What do you suggest to do in that case?
>
>I can do switch about i but I do not like that solution.
>I also do not see how #define A0 A[1] can help me in these cases.
>
>Uri



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.