From d63f95b89069797fb7b537da8fd7f7bdea9e7ac0 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 17 Sep 2013 13:12:08 +0000 Subject: [PATCH] BigMemoryObject::GetHeapMemorySizeOfObjs --- src/MEDCoupling/MEDCouplingRefCountObject.cxx | 25 ++++++++++++++++++- src/MEDCoupling/MEDCouplingRefCountObject.hxx | 4 +++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 15 ++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index 39794d403..e2b93ea4e 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -22,7 +22,6 @@ #include "MED_version.h" #include -#include using namespace ParaMEDMEM; @@ -78,6 +77,30 @@ std::size_t BigMemoryObject::getHeapMemorySize() const std::size_t ret(getHeapMemorySizeWithoutChildren()); std::vector v(getDirectChildren()); std::set s1,s2(v.begin(),v.end()); + return ret+GetHeapMemoryOfSet(s1,s2); +} + +std::size_t BigMemoryObject::GetHeapMemorySizeOfObjs(const std::vector& objs) +{ + std::size_t ret(0); + std::set s1,s2; + for(std::vector::const_iterator it0=objs.begin();it0!=objs.end();it0++) + { + if(*it0) + if(s1.find(*it0)==s1.end()) + { + std::vector 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& s1, std::set& s2) +{ + std::size_t ret(0); while(!s2.empty()) { std::set s3; diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx index 41c340d59..e0bf7950f 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.hxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -23,6 +23,7 @@ #include "MEDCoupling.hxx" +#include #include #include #include @@ -66,9 +67,12 @@ namespace ParaMEDMEM public: MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; MEDCOUPLING_EXPORT std::string getHeapMemorySizeStr() const; + MEDCOUPLING_EXPORT static std::size_t GetHeapMemorySizeOfObjs(const std::vector& objs); MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const = 0; MEDCOUPLING_EXPORT virtual std::vector getDirectChildren() const = 0; MEDCOUPLING_EXPORT virtual ~BigMemoryObject(); + private: + static std::size_t GetHeapMemoryOfSet(std::set& s1, std::set& s2); }; class RefCountObjectOnly diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 5f62bec58..3d412fd11 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -562,13 +562,13 @@ namespace ParaMEDMEM class BigMemoryObject { public: - std::size_t getHeapMemorySize() const; - std::string getHeapMemorySizeStr() const; - virtual std::size_t getHeapMemorySizeWithoutChildren() const; + std::size_t getHeapMemorySize() const throw(INTERP_KERNEL::Exception); + std::string getHeapMemorySizeStr() const throw(INTERP_KERNEL::Exception); + virtual std::size_t getHeapMemorySizeWithoutChildren() const throw(INTERP_KERNEL::Exception); virtual ~BigMemoryObject(); %extend { - virtual PyObject *getDirectChildren() const + virtual PyObject *getDirectChildren() const throw(INTERP_KERNEL::Exception) { std::vector c(self->getDirectChildren()); PyObject *ret(PyList_New(c.size())); @@ -576,6 +576,13 @@ namespace ParaMEDMEM PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(c[i]),SWIGTYPE_p_ParaMEDMEM__BigMemoryObject, 0 | 0 )); return ret; } + + static std::size_t GetHeapMemorySizeOfObjs(PyObject *objs) throw(INTERP_KERNEL::Exception) + { + std::vector cppObjs; + convertFromPyObjVectorOfObj(objs,SWIGTYPE_p_ParaMEDMEM__BigMemoryObject,"BigMemoryObject",cppObjs); + return BigMemoryObject::GetHeapMemorySizeOfObjs(cppObjs); + } } }; -- 2.39.2