[cgma-dev] r2274 - cgm/trunk/itaps

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue Nov 18 15:34:44 CST 2008


Author: kraftche
Date: 2008-11-18 15:34:44 -0600 (Tue, 18 Nov 2008)
New Revision: 2274

Modified:
   cgm/trunk/itaps/testgeom.cc
Log:
fix mismatched 'malloc' with 'delete []'

Modified: cgm/trunk/itaps/testgeom.cc
===================================================================
--- cgm/trunk/itaps/testgeom.cc	2008-11-18 21:29:35 UTC (rev 2273)
+++ cgm/trunk/itaps/testgeom.cc	2008-11-18 21:34:44 UTC (rev 2274)
@@ -60,9 +60,18 @@
     int arrAllocated;
      
   public:
-    SimpleArray()             : arr(0)         , arrSize(0), arrAllocated(0) {}
-    SimpleArray( unsigned s ) : arr( new T[s] ), arrSize(s), arrAllocated(s) {}
-    ~SimpleArray() { delete [] arr; }
+    SimpleArray() : arr(0) , arrSize(0), arrAllocated(0) {}
+    SimpleArray( unsigned s ) :arrSize(s), arrAllocated(s) {
+      arr = (T*)malloc(s*sizeof(T));
+      for (unsigned i = 0; i < s; ++i)
+        new (arr+i) T();
+    }
+    
+    ~SimpleArray() {
+      for (int i = 0; i < size(); ++i)
+        arr[i].~T();
+      free(arr);
+    }
 
     T**  ptr()            { return &arr; }
     int& size()           { return arrSize; }




More information about the cgma-dev mailing list