]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Modification of the getHeapMemorySize computation. DBugPolyhIntersector
authorageay <ageay>
Wed, 21 Aug 2013 15:01:04 +0000 (15:01 +0000)
committerageay <ageay>
Wed, 21 Aug 2013 15:01:04 +0000 (15:01 +0000)
src/MEDCoupling/MEDCouplingRefCountObject.cxx
src/MEDCoupling/MEDCouplingRefCountObject.hxx
src/MEDCoupling_Swig/MEDCouplingCommon.i

index b2374b980bddca7ab85176de6c96def3a7bdd007..49d954f8e217cd25a4692976e8409cdd75b27bd0 100644 (file)
@@ -21,6 +21,7 @@
 #include "MEDCouplingRefCountObject.hxx"
 #include "MED_version.h"
 
+#include <sstream>
 #include <set>
 
 using namespace ParaMEDMEM;
@@ -112,6 +113,46 @@ std::size_t RefCountObject::getHeapMemorySize() const
   return ret;
 }
 
+std::string RefCountObject::getHeapMemorySizeStr() const
+{
+  static const char *UNITS[4]={"B","kB","MB","GB"};
+  std::size_t m(getHeapMemorySize());
+  std::ostringstream oss; oss.precision(3);
+  std::size_t remain(0);
+  int i(0);
+  for(;i<4;i++)
+    {
+      if(m<1024)
+        {
+          oss << m;
+          if(remain!=0)
+            {
+              std::ostringstream oss2; oss2 << std::fixed << ((double)remain)/1024.;
+              std::string s(oss2.str());
+              s=s.substr(1,4);
+              std::size_t pos(s.find_last_not_of('0'));
+              if(pos==4)
+                oss << s;
+              else
+                oss << s.substr(0,pos+1);
+            }
+          oss << " " << UNITS[i];
+          break;
+        }
+      else
+        {
+          if(i!=3)
+            {
+              remain=(m%1024);
+              m/=1024;
+            }
+        }
+    }
+  if(i==4)
+    oss << m << " " << UNITS[3];
+  return oss.str();
+}
+
 bool RefCountObject::decrRef() const
 {
   bool ret=((--_cnt)==0);
index 883f4599de2c0fa64c597f1a85cdfefc8983726d..3d987d706e4825f11b83c4dbd412efc3df22a628 100644 (file)
@@ -24,6 +24,7 @@
 #include "MEDCoupling.hxx"
 
 #include <vector>
+#include <string>
 #include <cstddef>
 
 namespace ParaMEDMEM
@@ -69,6 +70,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT bool decrRef() const;
     MEDCOUPLING_EXPORT void incrRef() const;
     MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const;
+    MEDCOUPLING_EXPORT std::string getHeapMemorySizeStr() const;
     MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const = 0;
     MEDCOUPLING_EXPORT virtual std::vector<RefCountObject *> getDirectChildren() const = 0;
     MEDCOUPLING_EXPORT int getRCValue() const;
index c8339a20163f3fe276f6b02db766dafec3a6d52d..df1fa3a07030ee78f0944dbae0ceb6dde10f852c 100644 (file)
@@ -568,7 +568,8 @@ namespace ParaMEDMEM
     bool decrRef() const;
     void incrRef() const;
     int getRCValue() const;
-    virtual std::size_t getHeapMemorySize() const;
+    std::size_t getHeapMemorySize() const;
+    std::string RefCountObject::getHeapMemorySizeStr() const;
   };
 }