[geos-commits] r3357 - in trunk: include/geos/noding src/noding

svn_geos at osgeo.org svn_geos at osgeo.org
Thu May 12 03:18:07 EDT 2011


Author: strk
Date: 2011-05-12 00:18:07 -0700 (Thu, 12 May 2011)
New Revision: 3357

Modified:
   trunk/include/geos/noding/MCIndexSegmentSetMutualIntersector.h
   trunk/src/noding/MCIndexSegmentSetMutualIntersector.cpp
Log:
Don't let MCIndexSegmentSetMutualIntersector grow in memory on every new ::process call. Fixes bug #342.

Modified: trunk/include/geos/noding/MCIndexSegmentSetMutualIntersector.h
===================================================================
--- trunk/include/geos/noding/MCIndexSegmentSetMutualIntersector.h	2011-05-12 07:14:50 UTC (rev 3356)
+++ trunk/include/geos/noding/MCIndexSegmentSetMutualIntersector.h	2011-05-12 07:18:07 UTC (rev 3357)
@@ -59,6 +59,10 @@
 
 	~MCIndexSegmentSetMutualIntersector();
 
+	/* Returns a reference to a vector of MonotoneChain objects owned
+	 * by this class and destroyed on next call to ::process.
+	 * Copy them if you need them alive for longer.
+	 */
 	std::vector<index::chain::MonotoneChain *>& getMonotoneChains() 
 	{ 
 		return monoChains; 
@@ -71,6 +75,7 @@
 
 	void setBaseSegments(SegmentString::ConstVect* segStrings);
   
+	// NOTE: re-populates the MonotoneChain vector with newly created chains
 	void process(SegmentString::ConstVect* segStrings);
 
     class SegmentOverlapAction : public index::chain::MonotoneChainOverlapAction
@@ -107,9 +112,10 @@
 	// statistics
 	int nOverlaps;
 	
-	// memory management helper
-      typedef std::vector<std::vector<index::chain::MonotoneChain*>*> chainstore_mm_type;
-      chainstore_mm_type chainStore;
+	/* memory management helper, holds MonotoneChain objects used
+	 * in the SpatialIndex. It's cleared when the SpatialIndex is
+	 */
+	MonoChains chainStore;
       
 	void addToIndex( SegmentString * segStr);
 

Modified: trunk/src/noding/MCIndexSegmentSetMutualIntersector.cpp
===================================================================
--- trunk/src/noding/MCIndexSegmentSetMutualIntersector.cpp	2011-05-12 07:14:50 UTC (rev 3356)
+++ trunk/src/noding/MCIndexSegmentSetMutualIntersector.cpp	2011-05-12 07:18:07 UTC (rev 3357)
@@ -39,16 +39,16 @@
 void 
 MCIndexSegmentSetMutualIntersector::addToIndex(SegmentString* segStr)
 {
-    std::vector<MonotoneChain*>* segChains = 0;
-    segChains = MonotoneChainBuilder::getChains(segStr->getCoordinates(), segStr);
+    std::vector<MonotoneChain*> segChains;
+    MonotoneChainBuilder::getChains(segStr->getCoordinates(),
+      segStr, segChains);
 
-    chainStore.push_back(segChains);
-
-    for (std::size_t i = 0, n = segChains->size(); i < n; i++)
+    for (std::size_t i = 0, n = segChains.size(); i < n; i++)
     {
-        MonotoneChain * mc = (*segChains)[i];
+        MonotoneChain * mc = segChains[i];
         mc->setId(indexCounter++);
         index->insert(&(mc->getEnvelope()), mc);
+        chainStore.push_back(mc);
     }
 }
 
@@ -76,17 +76,17 @@
     }
 }
 
+/*private*/
 void 
 MCIndexSegmentSetMutualIntersector::addToMonoChains(SegmentString* segStr)
 {
-    MonoChains* segChains = 
-    	MonotoneChainBuilder::getChains(segStr->getCoordinates(), segStr);
+    MonoChains segChains;
+    MonotoneChainBuilder::getChains(segStr->getCoordinates(),
+                                    segStr, segChains);
 
-    chainStore.push_back(segChains);
-
-    for (MonoChains::size_type i = 0, ni = segChains->size(); i < ni; i++)
+    for (MonoChains::size_type i = 0, ni = segChains.size(); i < ni; i++)
     {
-        MonotoneChain* mc = (*segChains)[i];
+        MonotoneChain* mc = segChains[i];
         mc->setId( processCounter++ );
         monoChains.push_back(mc);
     }
@@ -109,17 +109,17 @@
 {
     delete index;
 
-    chainstore_mm_type::iterator end = chainStore.end();
-    for (chainstore_mm_type::iterator it = chainStore.begin(); it != end; ++it)
+    for (MonoChains::iterator it = chainStore.begin(), end = chainStore.end();
+           it != end; ++it)
     {
-        typedef std::vector<index::chain::MonotoneChain*> chainstore_type;
-        chainstore_type::iterator csend = (*it)->end();
-        for (chainstore_type::iterator csit = (*it)->begin(); csit != csend; ++csit)
-        {
-            delete *csit;
-        }
         delete *it;
     } 
+
+    for (MonoChains::iterator i = monoChains.begin(), e = monoChains.end();
+         i != e; i++)
+    {
+      delete *i;
+    }
 }
 
 void 
@@ -135,11 +135,18 @@
     }
 }
 
+/*public*/
 void 
 MCIndexSegmentSetMutualIntersector::process(SegmentString::ConstVect * segStrings)
 {
     processCounter = indexCounter + 1;
     nOverlaps = 0;
+
+    for (MonoChains::iterator i = monoChains.begin(), e = monoChains.end();
+         i != e; i++)
+    {
+      delete *i;
+    }
     monoChains.clear();
 
     for (std::size_t i = 0, n = segStrings->size(); i < n; i++)



More information about the geos-commits mailing list