From: jfa Date: Mon, 21 May 2007 07:03:36 +0000 (+0000) Subject: Fix implementation of GetAvailableMemory() method: use double variables for operation... X-Git-Tag: mergeto_BR_Dev_For_4_0_21May07~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cdbebb0523ddf69b5dfe1ddcb8e8fcbb088594dc;p=modules%2Fvisu.git Fix implementation of GetAvailableMemory() method: use double variables for operations on memory size to avoid overflow. --- diff --git a/src/PIPELINE/VISU_PipeLine.cxx b/src/PIPELINE/VISU_PipeLine.cxx index 0b8b845a..2d098595 100644 --- a/src/PIPELINE/VISU_PipeLine.cxx +++ b/src/PIPELINE/VISU_PipeLine.cxx @@ -391,21 +391,22 @@ VISU_PipeLine //---------------------------------------------------------------------------- -size_t +bool VISU_PipeLine -::CheckAvailableMemory(size_t theSize) +::CheckAvailableMemory(double theSize) { if(theSize < ULONG_MAX){ try{ - if(char *aCheck = new char[theSize]){ + size_t aSize = size_t(theSize); + if(char *aCheck = new char[aSize]){ delete [] aCheck; - return theSize; + return true; } }catch(std::bad_alloc& exc){ }catch(...){ } } - return 0; + return false; } @@ -416,19 +417,19 @@ VISU_PipeLine size_t theMinSize) { // Finds acceptable memory size by half-deflection methods - static size_t EPSILON = 2 * 1024; - size_t aMax = std::max(theSize, theMinSize); - size_t aMin = std::min(theSize, theMinSize); + static double EPSILON = 2 * 1024; + double aMax = std::max(theSize, theMinSize); + double aMin = std::min(theSize, theMinSize); //cout<<"GetAvailableMemory - "< 0 && (aMax - aMin) > EPSILON){ - size_t aRoot = (aMax + aMin) / 2; + while(!CheckAvailableMemory(aMax) && CheckAvailableMemory(aMin) && (aMax - aMin) > EPSILON){ + double aRoot = (aMax + aMin) / 2.; if(CheckAvailableMemory(aRoot)) aMin = aRoot; else aMax = aRoot; } //cout<<"; "<