From: eap Date: Mon, 24 Sep 2007 13:20:19 +0000 (+0000) Subject: PAL16631 (SALOME crash after a mesh computation failed due to lack of memory) X-Git-Tag: T_reliquat_2007~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2abe749fb540fa3b132b111a2f0bd89696b352f4;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="<