From: eap Date: Mon, 15 Jan 2007 10:17:32 +0000 (+0000) Subject: PAL14478( GHS3D memory ) X-Git-Tag: V3_2_5~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8639a956011add86b8ffd7ed6fcd6e633fc6ab5d;p=plugins%2Fhybridplugin.git PAL14478( GHS3D memory ) 1) adjust amount of memory GHS3D can allocate 2) remove useless methods --- diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index de26cc2..b779e95 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -399,6 +399,53 @@ static TCollection_AsciiString getTmpDir() return aTmpDir; } +//================================================================================ +/*! + * \brief Decrease amount of memory GHS3D may use until it can allocate it + * \param nbMB - memory size to adjust + * \param aLogFileName - file for GHS3D output + * \retval bool - false if GHS3D can not run for any reason + */ +//================================================================================ + +static bool adjustMemory(int & nbMB, const TCollection_AsciiString & aLogFileName) +{ + TCollection_AsciiString cmd( "ghs3d -m " ); + cmd += nbMB; + cmd += " 1>"; + cmd += aLogFileName; + + system( cmd.ToCString() ); // run + + // analyse log file + + FILE * aLogFile = fopen( aLogFileName.ToCString(), "r" ); + if ( aLogFile ) + { + bool memoryOK = true; + char * aPtr; + char aBuffer[ GHS3DPlugin_BUFLENGTH ]; + int aLineNb = 0; + do { + GHS3DPlugin_ReadLine( aPtr, aBuffer, aLogFile, aLineNb ); + if ( aPtr ) { + TCollection_AsciiString line( aPtr ); + if ( line.Search( "UNABLE TO ALLOCATE MEMORY" ) > 0 ) + memoryOK = false; + } + } while ( aPtr && memoryOK ); + + fclose( aLogFile ); + + if ( !memoryOK ) { + nbMB *= 0.75; + return adjustMemory( nbMB, aLogFileName ); + } + return true; + } + return false; +} + //============================================================================= /*! *Here we are going to use the GHS3D mesher @@ -481,8 +528,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, struct sysinfo si; int err = sysinfo( &si ); if ( err == 0 ) { + int MB = 0.9 * ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024; + adjustMemory( MB, aLogFileName ); memory = "-m "; - memory += int ( 0.5 * ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024 ); + memory += MB; } #endif @@ -533,48 +582,3 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return Ok; } - - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & GHS3DPlugin_GHS3D::SaveTo(ostream & save) -{ - return save; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & GHS3DPlugin_GHS3D::LoadFrom(istream & load) -{ - return load; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.SaveTo( save ); -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.LoadFrom( load ); -} diff --git a/src/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin_GHS3D.hxx index a3855ab..ebe1933 100644 --- a/src/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin_GHS3D.hxx @@ -43,11 +43,6 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); - ostream & SaveTo(ostream & save); - istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp); - friend istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp); - }; #endif