Salome HOME
Merge branch 'origin/V7_main'
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingRefCountObject.cxx
index 39794d403244ec9746667c94fc3018b66fcf281e..f30864a899b415fc96ce4a7b1953a3709333f9a8 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,7 +22,6 @@
 #include "MED_version.h"
 
 #include <sstream>
-#include <set>
 
 using namespace ParaMEDMEM;
 
@@ -78,6 +77,30 @@ std::size_t BigMemoryObject::getHeapMemorySize() const
   std::size_t ret(getHeapMemorySizeWithoutChildren());
   std::vector<const BigMemoryObject *> v(getDirectChildren());
   std::set<const BigMemoryObject *> s1,s2(v.begin(),v.end());
+  return ret+GetHeapMemoryOfSet(s1,s2);
+}
+
+std::size_t BigMemoryObject::GetHeapMemorySizeOfObjs(const std::vector<const BigMemoryObject *>& objs)
+{
+  std::size_t ret(0);
+  std::set<const BigMemoryObject *> s1,s2;
+  for(std::vector<const BigMemoryObject *>::const_iterator it0=objs.begin();it0!=objs.end();it0++)
+    {
+      if(*it0)
+        if(s1.find(*it0)==s1.end())
+          {
+            std::vector<const BigMemoryObject *> vTmp((*it0)->getDirectChildren());
+            s2.insert(vTmp.begin(),vTmp.end());
+            ret+=(*it0)->getHeapMemorySizeWithoutChildren();
+            s1.insert(*it0);
+          }
+    }
+  return ret+GetHeapMemoryOfSet(s1,s2);
+}
+
+std::size_t BigMemoryObject::GetHeapMemoryOfSet(std::set<const BigMemoryObject *>& s1, std::set<const BigMemoryObject *>& s2)
+{
+  std::size_t ret(0);
   while(!s2.empty())
     {
       std::set<const BigMemoryObject *> s3;