[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]
Gregory Berkolaiko wrote:
> 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)
> }
Since you may run multiple games with one civserver, the realloc (or
some other cleverness) is necessary.
> 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.
It's possible. The minimap variable is only allocated once - at the
beginning of each game, when generate_minimap is called - but the other
one has realloc called much more often. I considered renaming
generate_minimap as init_settlers() and moving the realloc call in
there. Should I do that?
> 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.
I tend to agree that having realloc be called every time is bad,
although I did measure both ways and on my system there was no
appreciable difference.
jason
[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
|
|