[mapguide-commits] r4388 - trunk/MgDev/Common/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Dec 8 17:47:31 EST 2009


Author: NormOlsen
Date: 2009-12-08 17:47:31 -0500 (Tue, 08 Dec 2009)
New Revision: 4388

Modified:
   trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
Log:
RFC #76, Trac ticket 1177.  Yet another submission fine tuning the ability of the Grid/Graticule feature to regulate the amouont of memory it consumes before throwing an exception.  I suspect there will be one more submission before this ticket is finished.  We need to submit as the application we are using to test  this new feature obtains the code changes via a SVN synch.

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp	2009-12-08 03:28:29 UTC (rev 4387)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp	2009-12-08 22:47:31 UTC (rev 4388)
@@ -27,7 +27,7 @@
 using namespace CSLibrary;
 
 const INT32 CCoordinateSystemGridGeneric::m_GridLineExceptionLevelK   =  50000000L;     //   50MB
-const INT32 CCoordinateSystemGridGeneric::m_GridRegionExceptionLevelK =  50000000L;      //  50MB
+const INT32 CCoordinateSystemGridGeneric::m_GridRegionExceptionLevelK =  30000000L;      //  30MB
 const INT32 CCoordinateSystemGridGeneric::m_GridTickExceptionLevelK   =  20000000L;      //  20MB
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-12-08 03:28:29 UTC (rev 4387)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-12-08 22:47:31 UTC (rev 4388)
@@ -31,11 +31,11 @@
 using namespace CSLibrary;
 
 #if !defined (_DEBUG)
-    // Include heap overhead estinated at 12 bytes in release mode.
+    // Include heap overhead estimated at 12 bytes in release mode.
     static const INT32 kMgHeapOverhead = 12;
     static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #else
-    // Include heap overhead estinated at 48 bytes in release mode.
+    // Include heap overhead estimated at 36 bytes in release mode.
     static const INT32 kMgHeapOverhead = 36;
     static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #endif
@@ -1107,8 +1107,16 @@
 {
     INT32 index;
     INT32 toAddCount;
+    INT32 maxValue;
+    INT32 memoryUse;
     Ptr<MgCoordinateSystemGridLine> aGridLine;
-    
+
+    maxValue = m_GridLineExceptionLevel - m_MemoryUse;
+    memoryUse = aGridLineCollection->GetMemoryUsage ();
+    if (memoryUse > maxValue)
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridLineCollection.AddCollection", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
     MG_TRY ()
         toAddCount = aGridLineCollection->GetCount ();
         for (index = 0;index < toAddCount;index += 1)
@@ -1116,7 +1124,7 @@
             aGridLine = aGridLineCollection->GetItem (index);
             this->Add (aGridLine);
         }
-    MG_CATCH_AND_THROW(L"CCoordinateSystemGridLineCollection::IndexOf")
+    MG_CATCH_AND_THROW(L"CCoordinateSystemGridLineCollection::AddCollection")
     return;
 }
 INT32 CCoordinateSystemGridLineCollection::SetGridLineExceptionLevel (INT32 memoryUseMax)
@@ -1234,9 +1242,18 @@
 {
     INT32 index;
     INT32 toAddCount;
+    INT32 memoryUse;
+    INT32 maxValue;
     Ptr<MgCoordinateSystemGridRegion> aGridRegion;
-    
+
+    maxValue = m_GridRegionExceptionLevel - m_MemoryUse;
+    memoryUse = aGridRegionCollection->GetMemoryUsage ();
+    if (memoryUse > maxValue)
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridRegionCollection.AddCollection", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
     MG_TRY ()
+        
         toAddCount = aGridRegionCollection->GetCount ();
         for (index = 0;index < toAddCount;index += 1)
         {
@@ -1364,8 +1381,16 @@
 {
     INT32 index;
     INT32 toAddCount;
+    INT32 maxValue;
+    INT32 memoryUse;
     Ptr<MgCoordinateSystemGridTick> aGridTick;
-    
+
+    maxValue = m_GridTickExceptionLevel - m_MemoryUse;
+    memoryUse = aGridTickCollection->GetMemoryUsage ();
+    if (memoryUse > maxValue)
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridTickCollection.AddCollection", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
     MG_TRY ()
         toAddCount = aGridTickCollection->GetCount ();
         for (index = 0;index < toAddCount;index += 1)

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-12-08 03:28:29 UTC (rev 4387)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-12-08 22:47:31 UTC (rev 4388)
@@ -27,9 +27,9 @@
 
 using namespace CSLibrary;
 
-const INT32 CCoordinateSystemMgrs::m_GridLineExceptionLevelK   =  50000000L;    //  50MB
-const INT32 CCoordinateSystemMgrs::m_GridRegionExceptionLevelK = 100000000L;    // 100MB
-const INT32 CCoordinateSystemMgrs::m_GridTickExceptionLevelK   =  20000000L;    //  20MB
+const INT32 CCoordinateSystemMgrs::m_GridLineExceptionLevelK   = 40000000L;    // 40MB
+const INT32 CCoordinateSystemMgrs::m_GridRegionExceptionLevelK = 60000000L;    // 60MB
+const INT32 CCoordinateSystemMgrs::m_GridTickExceptionLevelK   = 20000000L;    // 20MB
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Static constants.
@@ -388,6 +388,7 @@
     INT32 index;
     INT32 unitType;
     INT32 zoneCount;
+    INT32 zoneExceptionLevel;
     Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid;
     Ptr<MgCoordinateSystemGridLineCollection> aGridLineCollection;
     Ptr<CCoordinateSystemGridLineCollection> theGridLineCollection;
@@ -418,13 +419,14 @@
         zoneCount = m_ZoneCollection->GetCount ();
         for (index = 0;index < zoneCount;index += 1)
         {
+            zoneExceptionLevel = m_GridLineExceptionLevel - theGridLineCollection->GetMemoryUsage ();
             mgrsZoneGrid = m_ZoneCollection->GetItem (index);
             if (specIsGrid)
             {
                 // The specification calls for a grid.  The following function
                 // is smart enough to deal with the special nature of zones
                 // 31 through 37 at the higher northern latitudes.
-                aGridLineCollection = mgrsZoneGrid->GetGridLines (m_GridBoundary,specification,m_GridLineExceptionLevel);
+                aGridLineCollection = mgrsZoneGrid->GetGridLines (m_GridBoundary,specification,zoneExceptionLevel);
             }
             else
             {
@@ -432,7 +434,7 @@
                 // smart enough to deal with band X (which is 12 degrees high)
                 // and the special nature of zones 31 through 37 at the higher
                 // northern latitudes.
-                aGridLineCollection = mgrsZoneGrid->GetGraticuleLines (m_GridBoundary,specification,m_GridLineExceptionLevel);
+                aGridLineCollection = mgrsZoneGrid->GetGraticuleLines (m_GridBoundary,specification,zoneExceptionLevel);
             }
             if (aGridLineCollection != 0)
             {
@@ -449,6 +451,7 @@
 {
     INT32 index;
     INT32 zoneCount;
+    INT32 zoneExceptionLevel;
     Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid;
     Ptr<CCoordinateSystemGridRegionCollection> theGridRegionCollection;
 
@@ -464,9 +467,10 @@
         zoneCount = m_ZoneCollection->GetCount ();
         for (index = 0;index < zoneCount;index += 1)
         {
+            zoneExceptionLevel = m_GridRegionExceptionLevel - theGridRegionCollection->GetMemoryUsage ();
             mgrsZoneGrid = m_ZoneCollection->GetItem (index);
             Ptr<MgCoordinateSystemGridRegionCollection> aGridRegionCollection;
-            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (m_GridBoundary,specification,m_GridRegionExceptionLevel);
+            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (m_GridBoundary,specification,zoneExceptionLevel);
             theGridRegionCollection->AddCollection (aGridRegionCollection);
         }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrs::GetGridRegions")
@@ -563,6 +567,8 @@
 {
     INT32 index;
     INT32 zoneCount;
+    INT32 memoryUse;
+    INT32 maxValue;
     INT32 memoryGuess (-1);
 
     if (m_GridBoundary != 0)
@@ -572,7 +578,17 @@
         for (index = 0;index < zoneCount;index += 1)
         {
             Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid = m_ZoneCollection->GetItem (index);
-            memoryGuess += mgrsZoneGrid->ApproxGridRegionMemoryUsage (specification);
+            memoryUse = mgrsZoneGrid->ApproxGridRegionMemoryUsage (specification);
+            maxValue = 0x7FFF000 - memoryGuess;
+            if (memoryUse < maxValue)
+            {
+                memoryGuess += memoryUse;
+            }
+            else
+            {
+                memoryGuess = 0x7FFFFFFF;
+                break;
+            }
         }
     }
     return memoryGuess;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-12-08 03:28:29 UTC (rev 4387)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-12-08 22:47:31 UTC (rev 4388)
@@ -30,11 +30,11 @@
 using namespace CSLibrary;
 
 #if !defined (_DEBUG)
-    // Include heap overhead estinated at 12 bytes in release mode.
+    // Include heap overhead estimated at 12 bytes in release mode.
     static const INT32 kMgHeapOverhead = 12;
     static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #else
-    // Include heap overhead estinated at 48 bytes in release mode.
+    // Include heap overhead estimated at 36 bytes in release mode.
     static const INT32 kMgHeapOverhead = 36;
     static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #endif
@@ -240,6 +240,7 @@
 {
     INT32 regionSize;
     INT32 regionCount;
+    INT32 maxRegions;
     INT32 memoryGuess (0);
 
     // Estimate the size of a major region object.  Eventually, should include
@@ -263,6 +264,7 @@
                                                             sizeof (MgLineString) * 4 +
                                                             kMgSizeOfCoordinateXY * 4088;
     }
+    maxRegions = 0x7FFF000 / regionSize;
 
     MG_TRY ()
         if (specification->GetUnitType () == MgCoordinateSystemUnitType::Angular)
@@ -282,7 +284,16 @@
                 regionCount = mjrRegionCollection->GetCount ();
 
                 // Make a guess at the amount of memory required.
-                memoryGuess = regionSize * regionCount;
+                if (regionCount < maxRegions)
+                {
+                    memoryGuess = regionSize * regionCount;
+                }
+                else
+                {
+                    // Who knows what MAXINT will be in various environments.  We know
+                    // that memoryGuess is an INT32, so we use our own hard coded value.
+                    memoryGuess = 0x7FFFFFFF;
+                }
             }
         }
         else if (specification->GetUnitType () == MgCoordinateSystemUnitType::Linear)
@@ -318,7 +329,17 @@
                 INT32 horizontalCount = (endEast - beginEast) / 100000;
                 regionCount = horizontalCount * verticalCount;
 
-                memoryGuess = regionSize * regionCount;
+                // Make a guess at the amount of memory required.
+                if (regionCount < maxRegions)
+                {
+                    memoryGuess = regionSize * regionCount;
+                }
+                else
+                {
+                    // Who knows what MAXINT will be in various environments.  We know
+                    // that memoryGuess is an INT32, so we use our own hard coded value.
+                    memoryGuess = 0x7FFFFFFF;
+                }
             }
         }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrsZone::ApproxGridRegionMemoryUsage")

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-12-08 03:28:29 UTC (rev 4387)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-12-08 22:47:31 UTC (rev 4388)
@@ -29,11 +29,13 @@
 using namespace CSLibrary;
 
 #if !defined (_DEBUG)
-    // Include heap overhead estinated at 12 bytes in release mode.
-    static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + 12;
+    // Include heap overhead estimated at 12 bytes in release mode.
+    static const INT32 kMgHeapOverhead = 12;
+    static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #else
-    // Include heap overhead estinated at 48 bytes in release mode.
-    static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + 48;
+    // Include heap overhead estimated at 36 bytes in release mode.
+    static const INT32 kMgHeapOverhead = 36;
+    static const INT32 kMgSizeOfCoordinateXY = sizeof (MgCoordinateXY) + kMgHeapOverhead;
 #endif
 
 //=============================================================================



More information about the mapguide-commits mailing list