From: eap Date: Mon, 24 Sep 2007 13:49:46 +0000 (+0000) Subject: PAL16631 (SALOME crash after a mesh computation failed due to lack of memory) X-Git-Tag: V4_1_0a1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=490be5a7f03da355585e238e1f97bbec5b295e0e;p=modules%2Fsmesh.git PAL16631 (SALOME crash after a mesh computation failed due to lack of memory) use SMDS_MemoryLimit in CheckMemory() to know a lower memory limit --- diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 0de7c4af5..828658edb 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -43,6 +43,7 @@ using namespace std; #include #endif + //================================================================================ /*! * \brief Raise an exception if free memory (ram+swap) too low @@ -59,18 +60,35 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) if ( err ) return -1; + static int limit = -1; + if ( limit < 0 ) { + int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM + if (status >= 0 ) { + limit = WEXITSTATUS(status); + } + if ( limit < 20 ) + limit = 20; + else + limit = int( limit * 1.5 ); +#ifdef _DEBUG_ + cout << "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" << endl; +#endif + } + 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 ( freeMb > limit ) + return freeMb - limit; if ( doNotRaise ) return 0; - cout<<"SMDS_Mesh::CheckMemory() throws std::bad_alloc() as freeMb="<