]> OCCT Git - occt-copy.git/commitdiff
0022802: The memory allocated with an excess is not released
authorPKV <>
Thu, 8 Dec 2011 13:42:22 +0000 (13:42 +0000)
committerbugmaster <bugmaster@opencascade.com>
Mon, 5 Mar 2012 15:31:26 +0000 (19:31 +0400)
src/BOPTColStd/BOPTColStd_CArray1.cdl
src/BOPTColStd/BOPTColStd_CArray1.gxx
src/BOPTest/BOPTest_LowCommands.cxx
src/QAOCC/QAOCC.cxx

index 8de3aff957ee6256eac8f0cbf2df31ef593f4978..8a7ae4a6ed8e74ec1ca05afd37716dd7e8c2ad2e 100755 (executable)
@@ -31,7 +31,8 @@ is
     ---Purpose: 
     -- Prohibits the creator by copy
     --
-    Assign  (me:out;  Other : CArray1 from BOPTColStd) 
+    Assign  (me:out;  Other :  
+           CArray1 from BOPTColStd) 
        returns  CArray1 from BOPTColStd   
        is private; 
        ---C++:  alias  operator = 
@@ -39,7 +40,8 @@ is
     ---Purpose:  
     --  Prohibits the operator = 
     -- 
-    Resize(me: in out; theNewLength: Integer from Standard);
+    Resize(me: in out;  
+           theNewLength: Integer from Standard);
     ---Purpose:  
     --  destroy current content and realloc the new size
     --            
@@ -49,30 +51,37 @@ is
     --  Frees the  allocated   area  corresponding  to the
     --  array.  
     --  
-    Length (me) returns Integer from Standard;
+    Length (me)  
+       returns Integer from Standard;
     ---Purpose: 
     -- Returns the number of elements of <me> 
     --
-    Extent (me) returns Integer from Standard;
+    Extent (me)  
+       returns Integer from Standard;
     ---Purpose:  
     --  The  same  as Length(). 
     --- 
-    FactLength (me) returns Integer from Standard;
+    FactLength (me)  
+       returns Integer from Standard;
     ---Purpose:  
     --  Returns the number of elements of <me>.
     --- 
-    Append (me:out; Value: Array1Item)  
+    Append (me:out;  
+           Value: Array1Item)  
        returns Integer from Standard
        raises  OutOfMemory from Standard; 
     ---Purpose:  
     --  Remove the Item[Index]  from the array.
     ---
-    Remove (me:out; Index:Integer from Standard) 
+    Remove (me:out;  
+           Index:Integer from Standard) 
        raises  OutOfMemory from Standard; 
     ---Purpose:  
     --  Appends the Value at the end of me
     --- 
-    Value (me; Index:Integer from Standard) returns any Array1Item 
+    Value (me;  
+           Index:Integer from Standard)  
+       returns any Array1Item 
        ---C++: alias operator ()
        ---C++: return const & 
        raises OutOfRange from Standard;
@@ -81,7 +90,9 @@ is
     --  array.
     --          
     
-    ChangeValue (me: in out; Index:Integer from Standard) returns any Array1Item
+    ChangeValue (me: in out;  
+           Index:Integer from Standard)  
+       returns any Array1Item
        ---C++: alias operator ()
        ---C++: return & 
        raises OutOfRange from Standard; 
@@ -89,7 +100,8 @@ is
     --  Returns the value  of the Index-th element of the
     --  array.
 
-    SetBlockLength(me:out; aBL: Integer from Standard); 
+    SetBlockLength(me:out;  
+           aBL: Integer from Standard); 
     ---Purpose:  
     --  Sets the  size of the allocated block     
     --- 
@@ -97,16 +109,23 @@ is
        returns Integer from Standard;  
     ---Purpose:  
     --  Returns the current size of the allocated block   
-    --- 
-    IsInvalidIndex  (me; Index:Integer from Standard)  
+    ---   
+    IsInvalidIndex  (me;  
+           Index:Integer from Standard)  
        returns Boolean from Standard 
        is  private;   
     ---Purpose:   
     --  Checks the input value of an Index for validity in 
     --  array.              
-
+    --modified by NIZNHY-PKV Wed Nov 09 09:32:13 2011f 
+    Purge(me:out); 
+    ---Purpose:   
+    --  Release the memory that is allocated but unused. 
+    --     
+    --modified by NIZNHY-PKV Wed Nov 09 09:32:16 2011t
 fields
-
     myStart      : Address;
     myLength     : Integer; 
     myFactLength : Integer;
index 6b13fba59dc3e947da72b56a88cbd883e3cfab8f..3fff5a81aa59e89ecf4da1f4db0cc9ef3953e1dd 100755 (executable)
@@ -7,9 +7,8 @@
 //function : BOPTools_CArray1::BOPTools_CArray1
 //purpose  : 
 //=======================================================================
-  BOPTColStd_CArray1::BOPTColStd_CArray1
-       (const Standard_Integer aLength,
-       const Standard_Integer aBlockLength)
+BOPTColStd_CArray1::BOPTColStd_CArray1  (const Standard_Integer aLength,
+                                        const Standard_Integer aBlockLength)
   :  
   myStart(NULL), 
   myLength(0), 
@@ -23,7 +22,7 @@
 //function : Resize
 //purpose  : 
 //=======================================================================
-  void BOPTColStd_CArray1::Resize(const Standard_Integer aNL) 
+void BOPTColStd_CArray1::Resize(const Standard_Integer aNL) 
 {
   Array1Item* p = NULL;
   if (aNL>0) {
@@ -33,7 +32,7 @@
     
     if (!p) {
       Standard_OutOfMemory::Raise
-       ("IntBOPTools_CArray1 : Allocation failed.");
+       ("BOPTools_CArray1 : Allocation failed.");
     }
 
     else {
 //function : Remove
 //purpose  : 
 //=======================================================================
-  void BOPTColStd_CArray1::Remove(const Standard_Integer anInd)
+void BOPTColStd_CArray1::Remove(const Standard_Integer anInd)
 {
-  if (myIsAllocated)  {
-    if (IsInvalidIndex(anInd)) {
-      Standard_OutOfMemory::Raise
-       ("IntBOPTools_CArray1 : Attempt to remove inexisting Item.");
-    }
-    
-    const Standard_Integer aNFL=myFactLength-1;
+  if (!myIsAllocated)  {
+    return;
+  }
   
-    Array1Item *p=NULL;
-    p = new Array1Item[aNFL];
+  if (IsInvalidIndex(anInd)) {
+    Standard_OutOfMemory::Raise
+      ("BOPTools_CArray1 : Attempt to remove inexisting Item.");
+  }
   
-    if (!p) {
-      Standard_OutOfMemory::Raise
-       ("IntBOPTools_CArray1::Append: Allocation failed.");
+  const Standard_Integer aNFL=myFactLength-1;
+  Array1Item *p=NULL;
+  p = new Array1Item[aNFL];
+  
+  if (!p) {
+    Standard_OutOfMemory::Raise
+      ("BOPTools_CArray1::Append: Allocation failed.");
     }
-
-    Standard_Integer i, j, anIndx, iLength;
-
-    iLength=myLength;
-
-    anIndx=anInd-1;
-    for (i=0, j=0; i<myLength; ++i) {
-      if (i!=anIndx) {
-       p[j]= ((Array1Item *)myStart)[i];
-       j++;
-      }
+  
+  Standard_Integer i, j, anIndx, iLength;
+  
+  iLength=myLength;
+  
+  anIndx=anInd-1;
+  for (i=0, j=0; i<myLength; ++i) {
+    if (i!=anIndx) {
+      p[j]= ((Array1Item *)myStart)[i];
+      j++;
     }
-
-    Destroy();
-
-    myFactLength=aNFL;
-    myLength=iLength-1;
-    myIsAllocated=Standard_True;
-    myStart = (void*) p;
   }
+  
+  Destroy();
+  
+  myFactLength=aNFL;
+  myLength=iLength-1;
+  myIsAllocated=Standard_True;
+  myStart = (void*) p;
 }
 //=======================================================================
 //function : Append
     
     Destroy();
 
+    
     myFactLength=iLengthToAllocate;
     myIsAllocated=Standard_True;
     myStart = (void*) p;
 //function : IsInvalidIndex
 //purpose  : 
 //=======================================================================
-  Standard_Boolean BOPTColStd_CArray1::IsInvalidIndex
-        (const Standard_Integer anInd)const
+Standard_Boolean BOPTColStd_CArray1::IsInvalidIndex 
+  (const Standard_Integer anInd)const
 {
   Standard_Boolean aFlag;
   Standard_Integer anIndx=anInd-1;
 //function : Destroy
 //purpose  : 
 //=======================================================================
-  void BOPTColStd_CArray1::Destroy() 
+void BOPTColStd_CArray1::Destroy() 
 {
   if (myIsAllocated) {
     delete [] (Array1Item *)myStart;
     myLength=0;
     myStart=NULL;
   }
-  //myStart=NULL;
 }
+
 //=======================================================================
 //function : Length
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPTColStd_CArray1::Length() const
+Standard_Integer BOPTColStd_CArray1::Length() const
 {
   return myLength;
 }
 //function : Extent
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPTColStd_CArray1::Extent() const
+Standard_Integer BOPTColStd_CArray1::Extent() const
 {
   return myLength;
 }
 //function : FactLength
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPTColStd_CArray1::FactLength() const
+Standard_Integer BOPTColStd_CArray1::FactLength() const
 {
   return myFactLength;
 }
 //function : SetBlockLength
 //purpose  : 
 //=======================================================================
-  void BOPTColStd_CArray1::SetBlockLength(const Standard_Integer aBL) 
+void BOPTColStd_CArray1::SetBlockLength(const Standard_Integer aBL) 
 {
-  if (aBL > 0)
+  if (aBL > 0) {
     myBlockLength=aBL;
+  }
 }
 //=======================================================================
 //function : Value
 //purpose  : 
 //=======================================================================
-  const Array1Item& BOPTColStd_CArray1::Value
+const Array1Item& BOPTColStd_CArray1::Value
       (const Standard_Integer Index) const
 {
   if (IsInvalidIndex(Index)) {
 //function : ChangeValue
 //purpose  : 
 //=======================================================================
-  Array1Item& BOPTColStd_CArray1::ChangeValue
+Array1Item& BOPTColStd_CArray1::ChangeValue
       (const Standard_Integer Index) 
 {
   if (IsInvalidIndex(Index)) {
   }
   return ((Array1Item *)myStart)[Index-1];
 }
+//modified by NIZNHY-PKV Wed Nov 09 10:03:01 2011f
+//=======================================================================
+//function : Purge
+//purpose  : 
+//=======================================================================
+void BOPTColStd_CArray1::Purge() 
+{
+  if (!myIsAllocated) {
+    return;
+  }
+  //
+  if (myLength>0 && myLength<myFactLength) {
+    Standard_Integer i, aLength;
+    Array1Item *p = NULL;
+    //
+    p=new Array1Item[myLength];
+    if (!p) {
+      Standard_OutOfMemory::Raise
+       ("BOPTools_CArray1 : Allocation failed.");
+    }
+    //
+    for (i=0; i<myLength; i++) {
+      p[i]=((Array1Item *)myStart)[i];
+    }
+    //
+    aLength=myLength;
+    //
+    Destroy();
+    //
+    myIsAllocated=Standard_True;
+    myLength=aLength;
+    myFactLength=myLength;
+    myStart = (void*) p;
+  }
+}
+//modified by NIZNHY-PKV Wed Nov 09 10:03:07 2011t
+/*
+//=======================================================================
+//function : Dump
+//purpose  : 
+//=======================================================================
+void BOPTColStd_CArray1::Dump() const
+{
+  printf("\n--  BOPTColStd_CArray1::Dump --\n");
+  printf("myIsAllocated =%d\n", myIsAllocated);
+  printf("myLength      =%d\n", myLength);
+  printf("myFactLength  =%d\n", myFactLength);
+  printf("myBlockLength =%d\n", myBlockLength);
+}
+*/
index f39c12e76189f90df58ed5f654eeddf71ff9e437..8a52e995da7097db39da59376b07635f975cb7cc 100755 (executable)
@@ -58,6 +58,7 @@
 #include <OSD_Chronometer.hxx>
 
 #include <BRepTools.hxx>
+#include <BOPTColStd_CArray1OfInteger.hxx>
 
 static
   Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 
@@ -74,6 +75,12 @@ static
   void PrintState (Draw_Interpretor& aDI,
                   const TopAbs_State& aState);
 
+//modified by NIZNHY-PKV Thu Nov 10 12:11:15 2011f
+static
+  void DumpArray(const BOPTColStd_CArray1OfInteger& aC,
+              Draw_Interpretor& aDI);
+//modified by NIZNHY-PKV Thu Nov 10 12:11:18 2011t
+
 static  Standard_Integer bhaspc      (Draw_Interpretor& , Standard_Integer , const char** );
 static  Standard_Integer baddve      (Draw_Interpretor& , Standard_Integer , const char** );
 static  Standard_Integer bisclosed   (Draw_Interpretor& , Standard_Integer , const char** );
@@ -86,11 +93,8 @@ static  Standard_Integer brefine     (Draw_Interpretor& , Standard_Integer , con
 static  Standard_Integer bclassify   (Draw_Interpretor& , Standard_Integer , const char** );
 static  Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
 
-//modified by NIZNHY-PKV Mon May 29 11:44:24 2006f
 static  Standard_Integer bhole       (Draw_Interpretor& , Standard_Integer , const char** );
 static  Standard_Integer bxhole      (Draw_Interpretor& , Standard_Integer , const char** );
-//modified by NIZNHY-PKV Mon May 29 11:44:28 2006t
-
 //=======================================================================
 //function : LowCommands
 //purpose  : 
@@ -120,10 +124,8 @@ static  Standard_Integer bxhole      (Draw_Interpretor& , Standard_Integer , con
                                                                __FILE__, bclassify   , g);
   theCommands.Add("b2dclassify"  , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
                                                                __FILE__, b2dclassify , g);
-  //modified by NIZNHY-PKV Mon May 29 11:45:33 2006f
   theCommands.Add("bhole"   , "Use bhole"                     , __FILE__, bhole       , g);
   theCommands.Add("bxhole"  , "Use bxhole"                    , __FILE__, bxhole      , g);
-  //modified by NIZNHY-PKV Mon May 29 11:45:37 2006t
 }
 
 //=======================================================================
@@ -737,7 +739,6 @@ void PrintState (Draw_Interpretor& aDI,
   
 }
 //
-//modified by NIZNHY-PKV Mon May 29 11:40:29 2006f
 //=======================================================================
 //function : bhole
 //purpose  : 
@@ -901,4 +902,3 @@ Standard_Integer bxhole (Draw_Interpretor& aDI,
   //
   return 0;
 }
-//modified by NIZNHY-PKV Mon May 29 11:40:31 2006t
index 2ba6acc302b2fc99f3266ac4dfff6704af008293..53750815983da7e0ec2aa99d42545a5d67abd593 100755 (executable)
@@ -5256,6 +5256,56 @@ Standard_Integer OCC22736 (Draw_Interpretor& di, Standard_Integer argc, const ch
   return 0;
 }
 
+#include <BOPTColStd_CArray1OfInteger.hxx>
+//=======================================================================
+//function : DumpArray
+//purpose  : 
+//=======================================================================
+void DumpArray(const BOPTColStd_CArray1OfInteger& aC,
+              Draw_Interpretor& aDI)
+{
+  Standard_Integer iLength, iFactLength, iBlockLength;
+  //
+  iLength=aC.Length();
+  iFactLength=aC.FactLength();
+  iBlockLength=aC.BlockLength();
+  //
+  aDI<< "Length: " <<iLength << "\n";
+  aDI<< "FactLength: " <<iFactLength << "\n";
+  aDI<< "BlockLength: " <<iBlockLength << "\n";
+}
+//=======================================================================
+//function : bcarray
+//purpose  : 
+//=======================================================================
+Standard_Integer bcarray (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+       
+  if (argc != 1) {
+    di << "Usage : " << argv[0] << "\n";
+    return 1;
+  }
+
+  Standard_Integer i, aNb, aBL;
+  BOPTColStd_CArray1OfInteger aC;
+  //
+  aBL=100000;
+  aC.SetBlockLength(aBL);
+  //
+  for (i=1; i<=10; ++i) {
+    aC.Append(-i*10);
+  }
+  di<< "\nstate before release the unused memory\n";
+  DumpArray(aC, di);
+  //
+  aC.Purge();
+  //
+  di<< "\nstate after release the unused memory\n";
+  DumpArray(aC, di);
+  //
+  return 0;
+}
+
 void QAOCC::Commands(Draw_Interpretor& theCommands) {
   const char *group = "QAOCC";
 
@@ -5363,5 +5413,6 @@ void QAOCC::Commands(Draw_Interpretor& theCommands) {
   theCommands.Add("OCC22586", "OCC22586 shape resshape", __FILE__, OCC22586, group);
   theCommands.Add("OCC22736", "OCC22736 X_mirrorFirstPoint Y_mirrorFirstPoint X_mirrorSecondPoint Y_mirrorSecondPoint X_p1 Y_p1 X_p2 Y_p2", __FILE__, OCC22736, group);
   theCommands.Add("OCC22744", "OCC22744", __FILE__, OCC22744, group);
+  theCommands.Add("bcarray", "bcarray", __FILE__, bcarray, group);
   return;
 }