X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingRefCountObject.cxx;h=49d954f8e217cd25a4692976e8409cdd75b27bd0;hb=2bfeb4634e57f1036cb10eedd35ac75b3a2249fa;hp=443ae2cd8ff584b590f3cd78cd9cea3fec935eb7;hpb=6ce64f71ca5b7083df8b2177fab77f8ac55c6e42;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index 443ae2cd8..49d954f8e 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -21,6 +21,9 @@ #include "MEDCouplingRefCountObject.hxx" #include "MED_version.h" +#include +#include + using namespace ParaMEDMEM; const char *ParaMEDMEM::MEDCouplingVersionStr() @@ -46,6 +49,28 @@ int ParaMEDMEM::MEDCouplingSizeOfVoidStar() return 8*sizeof(std::size_t); } +/*! + * If true is returned it is a LittleEndian machine. + * If false it is a BigEndian machine. + * \return the coding mode of integers of the machine. + */ +bool ParaMEDMEM::MEDCouplingByteOrder() +{ + unsigned int x(1); + unsigned char *xc(reinterpret_cast(&x)); + return xc[0]==1; +} + +const char *ParaMEDMEM::MEDCouplingByteOrderStr() +{ + static const char LITTLEENDIAN_STR[]="LittleEndian"; + static const char BIGENDIAN_STR[]="BigEndian"; + if(MEDCouplingByteOrder()) + return LITTLEENDIAN_STR; + else + return BIGENDIAN_STR; +} + RefCountObject::RefCountObject():_cnt(1) { } @@ -63,6 +88,71 @@ RefCountObject& RefCountObject::operator=(const RefCountObject& other) return *this; } +std::size_t RefCountObject::getHeapMemorySize() const +{ + std::size_t ret(getHeapMemorySizeWithoutChildren()); + std::vector v(getDirectChildren()); + std::set s1,s2(v.begin(),v.end()); + while(!s2.empty()) + { + std::set s3; + for(std::set::const_iterator it=s2.begin();it!=s2.end();it++) + { + if(s1.find(*it)==s1.end()) + { + ret+=(*it)->getHeapMemorySizeWithoutChildren(); + s1.insert(*it); + std::vector v2((*it)->getDirectChildren()); + for(std::vector::const_iterator it2=v2.begin();it2!=v2.end();it2++) + if(s1.find(*it2)==s1.end()) + s3.insert(*it2); + } + } + s2=s3; + } + 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);