Salome HOME
PAL16774,PAL16631(SALOME crash after a mesh computation that failed because of lack...
authoreap <eap@opencascade.com>
Mon, 10 Sep 2007 14:21:47 +0000 (14:21 +0000)
committereap <eap@opencascade.com>
Mon, 10 Sep 2007 14:21:47 +0000 (14:21 +0000)
-  bool CheckMemory()
+  int CheckMemory() - return size of free memory

src/SMDS/SMDS_Mesh.cxx
src/SMDS/SMDS_Mesh.hxx

index 9c48382748d983e54b6c25418aa5ec990639974b..0de7c4af5b9c3193eac5eda1f327ef0a7bad1e4b 100644 (file)
@@ -46,27 +46,34 @@ using namespace std;
 //================================================================================
 /*!
  * \brief Raise an exception if free memory (ram+swap) too low
- * \param doNotRaise - if true, suppres exception, just return bool
- * \retval bool - true if there is enough memory
+ * \param doNotRaise - if true, suppres exception, just return free memory size
+ * \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
   struct sysinfo si;
   int err = sysinfo( &si );
   if ( err )
-    return true;
-  
-  int freeMbyte = ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024;
-  if ( freeMbyte > 4 )
-    return true;
+    return -1;
+
+  const unsigned long Mbyte = 1024 * 1024;
+  // compute separately to avoid overflow
+  int freeMb =
+    ( si.freeram  * si.mem_unit ) / Mbyte +
+    ( si.freeswap * si.mem_unit ) / Mbyte;
+
+  if ( freeMb > 4 )
+    return freeMb;
+
   if ( doNotRaise )
-    return false;
+    return 0;
+  cout<<"SMDS_Mesh::CheckMemory() throws std::bad_alloc() as freeMb="<<freeMb<<endl;
   throw std::bad_alloc();
 #else
-  return true;
+  return -1;
 #endif
 }
 
index 324b961acdee410165999c4fd2520d0b04b52a68..da2bbd079c6cdac9e3bab0a6bf6e3a6d7ec790a9 100644 (file)
@@ -493,10 +493,10 @@ public:
 
   /*!
    * \brief Raise an exception if free memory (ram+swap) too low
-    * \param doNotRaise - if true, suppres exception, just return bool
-    * \retval bool - true if there is enough memory
+    * \param doNotRaise - if true, suppres exception, just return free memory size
+    * \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 MinNodeID() const;