[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]
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.
- [Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays,
Gregory Berkolaiko <=
[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays, Per I. Mathisen, 2003/09/19
[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays, Per I. Mathisen, 2003/09/19
|
|