[Avida-cvs] [avida-svn] r418 - trunk/source/cpu

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Dec 9 10:15:48 PST 2005


Author: brysonda
Date: 2005-12-09 13:15:48 -0500 (Fri, 09 Dec 2005)
New Revision: 418

Modified:
   trunk/source/cpu/cCPUMemory.cc
   trunk/source/cpu/cCPUMemory.h
Log:
Adjust cCPUMemory to use tManagedPointerArray for memory flags to reduce the pathological allocation behavior associated with resizing (used frequently in 4Stack and SMT).

Also added in a minimum allocation increment for SloppyResize to prevent the rapid fire calls that would occur on writing into a new memory space.  This does of course have possible side effect of increasing (avida) memory usage slightly when many small memory spaces are used (each with < ~10-20 instructions).

Modified: trunk/source/cpu/cCPUMemory.cc
===================================================================
--- trunk/source/cpu/cCPUMemory.cc	2005-12-08 21:21:40 UTC (rev 417)
+++ trunk/source/cpu/cCPUMemory.cc	2005-12-09 18:15:48 UTC (rev 418)
@@ -11,6 +11,7 @@
 
 using namespace std;
 
+const int MEMORY_INCREASE_MINIMUM = 10;
 const double MEMORY_INCREASE_FACTOR = 1.5;
 const double MEMORY_SHRINK_TEST_FACTOR = 4.0;
 
@@ -57,9 +58,10 @@
   const int array_size = genome.GetSize();
 
   // Determine if we need to adjust the allocated array sizes...
-  if (new_size > array_size ||
-      new_size * MEMORY_SHRINK_TEST_FACTOR < array_size) {
-    const int new_array_size = (int) (new_size * MEMORY_INCREASE_FACTOR);
+  if (new_size > array_size || new_size * MEMORY_SHRINK_TEST_FACTOR < array_size) {
+    int new_array_size = (int) (new_size * MEMORY_INCREASE_FACTOR);
+    const int new_array_min = new_size + MEMORY_INCREASE_MINIMUM;
+		if (new_array_min > new_array_size) new_array_size = new_array_min;
     genome.Resize(new_array_size);
     flag_array.Resize(new_array_size);
   }

Modified: trunk/source/cpu/cCPUMemory.h
===================================================================
--- trunk/source/cpu/cCPUMemory.h	2005-12-08 21:21:40 UTC (rev 417)
+++ trunk/source/cpu/cCPUMemory.h	2005-12-09 18:15:48 UTC (rev 418)
@@ -11,8 +11,8 @@
 #ifndef GENOME_HH
 #include "cGenome.h"
 #endif
-#ifndef TARRAY_HH
-#include "tArray.h"
+#ifndef tManagedPointerArray_h
+#include "tManagedPointerArray.h"
 #endif
 #ifndef MEMORY_FLAGS_HH
 #include "cMemoryFlags.h"
@@ -26,7 +26,7 @@
 
 class cCPUMemory : public cGenome {
 private:
-  tArray<cMemoryFlags> flag_array;
+  tManagedPointerArray<cMemoryFlags> flag_array;
 
   // A collection of sloppy instructions to perform oft-used functions that
   // will need to be cleaned up after this is run.




More information about the Avida-cvs mailing list