PAL16774,PAL16631(SALOME crash after a mesh computation that failed because of lack of memory)

-  bool CheckMemory()
+  int CheckMemory() - return size of free memory
This commit is contained in:
eap 2007-09-11 06:12:14 +00:00
parent 9cfa837a1d
commit 7ff996b8f5
2 changed files with 20 additions and 13 deletions

View File

@ -46,27 +46,34 @@ using namespace std;
//================================================================================ //================================================================================
/*! /*!
* \brief Raise an exception if free memory (ram+swap) too low * \brief Raise an exception if free memory (ram+swap) too low
* \param doNotRaise - if true, suppres exception, just return bool * \param doNotRaise - if true, suppres exception, just return free memory size
* \retval bool - true if there is enough memory * \retval int - amount of available memory in MB or negative number in failure case
*/ */
//================================================================================ //================================================================================
bool SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
{ {
#ifndef WIN32 #ifndef WIN32
struct sysinfo si; struct sysinfo si;
int err = sysinfo( &si ); int err = sysinfo( &si );
if ( err ) if ( err )
return true; return -1;
int freeMbyte = ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024; const unsigned long Mbyte = 1024 * 1024;
if ( freeMbyte > 4 ) // compute separately to avoid overflow
return true; int freeMb =
( si.freeram * si.mem_unit ) / Mbyte +
( si.freeswap * si.mem_unit ) / Mbyte;
if ( freeMb > 4 )
return freeMb;
if ( doNotRaise ) if ( doNotRaise )
return false; return 0;
cout<<"SMDS_Mesh::CheckMemory() throws std::bad_alloc() as freeMb="<<freeMb<<endl;
throw std::bad_alloc(); throw std::bad_alloc();
#else #else
return true; return -1;
#endif #endif
} }

View File

@ -484,10 +484,10 @@ public:
/*! /*!
* \brief Raise an exception if free memory (ram+swap) too low * \brief Raise an exception if free memory (ram+swap) too low
* \param doNotRaise - if true, suppres exception, just return bool * \param doNotRaise - if true, suppres exception, just return free memory size
* \retval bool - true if there is enough memory * \retval int - amount of available memory in MB or negative number in failure case
*/ */
static bool CheckMemory(const bool doNotRaise=false) throw (std::bad_alloc); static int CheckMemory(const bool doNotRaise=false) throw (std::bad_alloc);
int MaxNodeID() const; int MaxNodeID() const;
int MinNodeID() const; int MinNodeID() const;