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
Subject: [Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Wed, 17 Sep 2003 11:30:10 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, 17 Sep 2003, Jason Short wrote:

> 
> There are two remaining MAP_MAX_WIDTH * MAP_MAX_HEIGHT arrays: in 
> settlers.c.
> 
> These present problems when increasing MAP_MAX_WIDTH and MAP_MAX_HEIGHT. 
>   They also break under gen-topologies.  And of course they waste memory 
> in general.
> 
> The attached patch replaces them with dynamic arrays, as is used 
> everywhere else.  Autogames are identical and slightly faster (probably 
> because of the direct memset to territory).

Also smaller memory chunks make a surprising difference.

BTW, I appreciate the elegance of using  
        mem = realloc(mem, ..)                  (1)
instead of
        if (!mem) {
          mem = malloc(...)                     (2)
        }
but I suspect some (naive) realloc implementations act like this:
        new = malloc(..)
        memcpy(old, new, ..)
        free(old)
        return new
which means you are wasting a lot of time.

Even cleverer implementations do a lot of cruft checks, to see if some 
memory could be split off etc.  I think using good old (1) is more 
transparent and reliable.

G.





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