Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about changing my data structure

Author: Uri Blass

Date: 06:49:20 07/17/03

Go up one level in this thread


On July 17, 2003 at 09:03:33, Uri Blass wrote:

>On July 17, 2003 at 07:01:10, Dave Gomboc wrote:
>
>>On July 17, 2003 at 05:06:16, Uri Blass wrote:
>>
>>>Note that the name of the arrays that I have is different but I replaced the
>>>names to make it easy to understand the problem.
>>>
>>>I have an array A[64][8]
>>>
>>>I want to replace it by 8 arrays A0[64],A1[64],...A7[64] when A[i][j]=Aj[i]
>>>
>>>What is the best way to do it?
>>
>>
>>I think you want something like
>>
>>    typedef /* your type here */ element_type;
>>
>>    element_type big_array[8][64];
>>    const element_type zeroth_array [64] = big_array[0];
>>    const element_type first_array  [64] = big_array[1];
>>    const element_type second_array [64] = big_array[2];
>>    const element_type third_array  [64] = big_array[3];
>>    const element_type fourth_array [64] = big_array[4];
>>    const element_type fifth_array  [64] = big_array[5];
>>    const element_type sixth_array  [64] = big_array[6];
>>    const element_type seventh_array[64] = big_array[7];
>>
>>Then you can refer either to big_array[0][n] or to zeroth_array[n].
>>
>>The syntax is probably not exactly correct, my machine is busy so I didn't put
>>it through a compiler.
>
>You are right that the syntex is not correct.
>When I use int instead of element type I get the error
>
>array initialization needs curly braces
>
>Maybe I need the following syntex except using significant names to the array
>and not big_array, zeroth_array,...:
>
>int big_array[8][64];
>int * const zeroth_array = big_array[0];
>int * const first_array = big_array[1];
>
>Uri

Again I find that it is slower for me.
Maybe this is a statistical error and I should not care about it but for some
reason int * const is slower for me than the previous code.


It seems better to have in data.c
int big_array[8][64];
int zeroth_array[64];
int first_array[64];
...
int eight_array[64];

and in data.h
extern int big_array[8][64];
extern int zeroth_array[64];
extern int first_array[64];
...
extern int eight_array[64];


and not

int big_array[8][64];
int * const zeroth_array = big_array[0];
int * const first_array = big_array[1];

extern int big_array[8][64];
extern int * const zeroth_array;
extern int * const first_array;

I thought that maybe the reason is different order of arrays but the difference
of few % is also when I put the arrays in the same order(the original order was
not 0,1,2,3,... and I have other names and not names like first_array)

Uri



This page took 0 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.