]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix implementation of GetAvailableMemory() method: use double variables for operation...
authorjfa <jfa@opencascade.com>
Mon, 21 May 2007 07:03:36 +0000 (07:03 +0000)
committerjfa <jfa@opencascade.com>
Mon, 21 May 2007 07:03:36 +0000 (07:03 +0000)
src/PIPELINE/VISU_PipeLine.cxx
src/PIPELINE/VISU_PipeLine.hxx

index 0b8b845a211146b8d955e0e922ecb27c815731e5..2d098595a09d157b5ff1fbf6dba338ef77fc9932 100644 (file)
@@ -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 - "<<aMax<<"; "<<aMin;
-  while(CheckAvailableMemory(aMax) == 0 && CheckAvailableMemory(aMin) > 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<<"; "<<aMax<<endl;
-  return aMax;
+  return (size_t)aMax;
 }
 
 
index 3590ae9c7b6c1ec08a486be653fb2fc5c4f5ec95..73a29173eaa94633283bc33fab74da2ebcb1032f 100644 (file)
@@ -173,9 +173,9 @@ public:
 
   //----------------------------------------------------------------------------
   static
-  size_t
-  CheckAvailableMemory(size_t theSize);
-  
+  bool
+  CheckAvailableMemory(double theSize);
+
   static
   size_t
   GetAvailableMemory(size_t theSize,