Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays
Home

[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays
From: Ross Wetmore <rwetmore@xxxxxxxxxxxx>
Date: Fri, 19 Sep 2003 11:06:08 -0400

The main argument was more to do with pre-computing parts of the index
computation, i.e. using a bastardized 2-D form as an array of pointers
rather than a simple 2-D array.

Array and computed forms are optimized equivalently by most compilers
if you are careful to make sure the variables are marked local/const,
which is where Raimar introduced his biases against the computed form.

Using macros to make the computations as similar and easily recognized
by the compiler, even when used for other purposes can even enhance the
optimization effects.


As Jason pointes out, it is the hardcoded elements of the array form
that make it less suitable, and more difficult to code for in general.
Although because of the "native coordinate" form underlying even
gen-topologies, there will always be a rectangular 2-D form that could
be used for mem access as opposed to the linear index form used now.
Note, the compiler always converts 2-D to a linear index for array
lookups, so arrays really just hide access to the linear form rather
than doing anything fundamentally different.

Cheers,
RossW
=====

Jason Short wrote:
Gregory Berkolaiko wrote:

On Thu, 18 Sep 2003, Bursig Rafal wrote:


Sorry this msg was rejected by RT then I sent it to list



I remember there was a big discussion on this with Ross and Raimar very active participants. IIRC there was no verdict as there were argument both for and against using array[x][y] vs array[x * size + y]


I prefer the array[x][y] form. Except that it breaks under gen-topologies and consumes more memory.

jason




[Prev in Thread] Current Thread [Next in Thread]