From 8639a956011add86b8ffd7ed6fcd6e633fc6ab5d Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 15 Jan 2007 10:17:32 +0000 Subject: [PATCH] PAL14478( GHS3D memory ) 1) adjust amount of memory GHS3D can allocate 2) remove useless methods --- src/GHS3DPlugin_GHS3D.cxx | 96 ++++++++++++++++++++------------------- src/GHS3DPlugin_GHS3D.hxx | 5 -- 2 files changed, 50 insertions(+), 51 deletions(-) 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 -- 2.39.2