Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: memory performance, memory allocation under windows questions

Author: Dieter Buerssner

Date: 03:13:13 12/10/01

Go up one level in this thread


On December 09, 2001 at 21:09:17, martin fierz wrote:

>i have written a checkers interface and a checkers engine, and recently i made a
>change so that the user can set the hashtable size in the interface and it is
>communicated to the engine.
>up to now, my code looked like this:
>
>// global variables
>struct hashentry hashtable[BIGNUMBER];
>
>now it looks like this:
>
>// global variables
>struct hashentry *hashtable;
>
>// initialization
>hashtable = malloc(BIGNUMBER*sizeof(struct hashentry));
>
>later in the code i access the hashtable just as before with hashtable[i].
>i would have expected these two approaches to be equivalent, but the new one
>drops a few % of speed overall.

While the C code accessing the table looks the same, the machine code will be
different. The pointer approach needs one indirection more (the pointer must be
loaded into a register, while adressing. The array will be accessed without this
indirection. It has a constant adress in memory, that is known at link time).

But still, your few percents look a bit much. Because the adressing should take
much less time, than the actual memory access.

I have seen such figures too, and wondered. In my case, interestingly some
malloced memory seemed faster.

Regards,
Dieter




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.