Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: Freeciv Networking/Mac Server patches
Home

[Freeciv-Dev] Re: Freeciv Networking/Mac Server patches

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Freeciv Networking/Mac Server patches
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sat, 2 Sep 2000 22:14:22 +1100 (EST)

David Pfitzner wrote:
> On Sun, 20 Aug 2000 Andy Black <ablack@xxxxxxxxxxxxxx> wrote:

> > aitech.c.diff
> >     alternate memory allocation. needed to compile.  (please comit)

> I'm assuming only "unsigned char cache[A_LAST][A_LAST]" was the real
> problem, (size 40,000 bytes, > 32,768 bytes?), so attached patch changes
> only this one (for all platforms), to allocated (once, static, never
> freed).  (Also renamed unrelated variable 'c' to descriptive name.)

Since we only increment the cache values and test for non-zero, 
can instead use a bit-vector, using 1/8'th the memory and presumably 
not having problem with array size on eg mac.  (Also some people might 
not have liked my previous patch "wasting" 40k ;-)

This patch changes the cache variable to use bit vector method instead
(compare 'used_ids' in srv_main.c).

-- David
--- freeciv-mod/ai/aitech.c     Sat Sep  2 21:47:03 2000
+++ fc-adv/ai/aitech.c  Sat Sep  2 21:47:10 2000
@@ -203,7 +203,10 @@
   int values[A_LAST];
   int goal_values[A_LAST];
   int prereq[A_LAST];
-  unsigned char cache[A_LAST][A_LAST];
+  unsigned char cache[A_LAST][A_LAST/8+1];   /* bit vector for tech pairs */
+
+#define CACHE_SET(i,k)  cache[i][(k)/8] |= (1<<((k)%8))
+#define CACHE_TEST(i,k) cache[i][(k)/8] &  (1<<((k)%8))
   
   num_cities_nonzero = MAX(1, city_list_size(&pplayer->cities));
   memset(values, 0, sizeof(values));
@@ -217,7 +220,7 @@
       find_prerequisites(pplayer, i, prereq);
       for (k = A_FIRST; k < game.num_tech_types; k++) {
         if (prereq[k]) {
-          cache[i][k]++;
+         CACHE_SET(i,k);
           values[k] += pplayer->ai.tech_want[i] / j;
         }
       }
@@ -227,7 +230,7 @@
   for (i = A_FIRST; i < game.num_tech_types; i++) {
     if (pplayer->ai.tech_turns[i]) {
       for (k = A_FIRST; k < game.num_tech_types; k++) {
-        if (cache[i][k]) {
+       if (CACHE_TEST(i,k)) {
           goal_values[i] += values[k];
         }
       }
@@ -272,6 +275,8 @@
   }
   return;
 }
+#undef CACHE_SET
+#undef CACHE_TEST
 
 static void ai_select_tech_goal(struct player *pplayer, struct ai_choice 
*choice)
 {

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