1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0022802: The memory allocated with an excess is not released

This commit is contained in:
PKV 2011-12-08 13:42:22 +00:00 committed by bugmaster
parent 3492f422b9
commit 251450e53f
4 changed files with 194 additions and 72 deletions

View File

@ -31,7 +31,8 @@ is
---Purpose: ---Purpose:
-- Prohibits the creator by copy -- Prohibits the creator by copy
-- --
Assign (me:out; Other : CArray1 from BOPTColStd) Assign (me:out; Other :
CArray1 from BOPTColStd)
returns CArray1 from BOPTColStd returns CArray1 from BOPTColStd
is private; is private;
---C++: alias operator = ---C++: alias operator =
@ -39,7 +40,8 @@ is
---Purpose: ---Purpose:
-- Prohibits the operator = -- Prohibits the operator =
-- --
Resize(me: in out; theNewLength: Integer from Standard); Resize(me: in out;
theNewLength: Integer from Standard);
---Purpose: ---Purpose:
-- destroy current content and realloc the new size -- destroy current content and realloc the new size
-- --
@ -49,30 +51,37 @@ is
-- Frees the allocated area corresponding to the -- Frees the allocated area corresponding to the
-- array. -- array.
-- --
Length (me) returns Integer from Standard; Length (me)
returns Integer from Standard;
---Purpose: ---Purpose:
-- Returns the number of elements of <me> -- Returns the number of elements of <me>
-- --
Extent (me) returns Integer from Standard; Extent (me)
returns Integer from Standard;
---Purpose: ---Purpose:
-- The same as Length(). -- The same as Length().
--- ---
FactLength (me) returns Integer from Standard; FactLength (me)
returns Integer from Standard;
---Purpose: ---Purpose:
-- Returns the number of elements of <me>. -- Returns the number of elements of <me>.
--- ---
Append (me:out; Value: Array1Item) Append (me:out;
Value: Array1Item)
returns Integer from Standard returns Integer from Standard
raises OutOfMemory from Standard; raises OutOfMemory from Standard;
---Purpose: ---Purpose:
-- Remove the Item[Index] from the array. -- 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; raises OutOfMemory from Standard;
---Purpose: ---Purpose:
-- Appends the Value at the end of me -- 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++: alias operator ()
---C++: return const & ---C++: return const &
raises OutOfRange from Standard; raises OutOfRange from Standard;
@ -81,7 +90,9 @@ is
-- array. -- 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++: alias operator ()
---C++: return & ---C++: return &
raises OutOfRange from Standard; raises OutOfRange from Standard;
@ -89,7 +100,8 @@ is
-- Returns the value of the Index-th element of the -- Returns the value of the Index-th element of the
-- array. -- array.
SetBlockLength(me:out; aBL: Integer from Standard); SetBlockLength(me:out;
aBL: Integer from Standard);
---Purpose: ---Purpose:
-- Sets the size of the allocated block -- Sets the size of the allocated block
--- ---
@ -97,16 +109,23 @@ is
returns Integer from Standard; returns Integer from Standard;
---Purpose: ---Purpose:
-- Returns the current size of the allocated block -- Returns the current size of the allocated block
--- ---
IsInvalidIndex (me; Index:Integer from Standard) IsInvalidIndex (me;
Index:Integer from Standard)
returns Boolean from Standard returns Boolean from Standard
is private; is private;
---Purpose: ---Purpose:
-- Checks the input value of an Index for validity in -- Checks the input value of an Index for validity in
-- array. -- 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 fields
myStart : Address; myStart : Address;
myLength : Integer; myLength : Integer;
myFactLength : Integer; myFactLength : Integer;

View File

@ -7,9 +7,8 @@
//function : BOPTools_CArray1::BOPTools_CArray1 //function : BOPTools_CArray1::BOPTools_CArray1
//purpose : //purpose :
//======================================================================= //=======================================================================
BOPTColStd_CArray1::BOPTColStd_CArray1 BOPTColStd_CArray1::BOPTColStd_CArray1 (const Standard_Integer aLength,
(const Standard_Integer aLength, const Standard_Integer aBlockLength)
const Standard_Integer aBlockLength)
: :
myStart(NULL), myStart(NULL),
myLength(0), myLength(0),
@ -23,7 +22,7 @@
//function : Resize //function : Resize
//purpose : //purpose :
//======================================================================= //=======================================================================
void BOPTColStd_CArray1::Resize(const Standard_Integer aNL) void BOPTColStd_CArray1::Resize(const Standard_Integer aNL)
{ {
Array1Item* p = NULL; Array1Item* p = NULL;
if (aNL>0) { if (aNL>0) {
@ -33,7 +32,7 @@
if (!p) { if (!p) {
Standard_OutOfMemory::Raise Standard_OutOfMemory::Raise
("IntBOPTools_CArray1 : Allocation failed."); ("BOPTools_CArray1 : Allocation failed.");
} }
else { else {
@ -48,43 +47,44 @@
//function : Remove //function : Remove
//purpose : //purpose :
//======================================================================= //=======================================================================
void BOPTColStd_CArray1::Remove(const Standard_Integer anInd) void BOPTColStd_CArray1::Remove(const Standard_Integer anInd)
{ {
if (myIsAllocated) { if (!myIsAllocated) {
if (IsInvalidIndex(anInd)) { return;
Standard_OutOfMemory::Raise
("IntBOPTools_CArray1 : Attempt to remove inexisting Item.");
}
const Standard_Integer aNFL=myFactLength-1;
Array1Item *p=NULL;
p = new Array1Item[aNFL];
if (!p) {
Standard_OutOfMemory::Raise
("IntBOPTools_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++;
}
}
Destroy();
myFactLength=aNFL;
myLength=iLength-1;
myIsAllocated=Standard_True;
myStart = (void*) p;
} }
if (IsInvalidIndex(anInd)) {
Standard_OutOfMemory::Raise
("BOPTools_CArray1 : Attempt to remove inexisting Item.");
}
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++;
}
}
Destroy();
myFactLength=aNFL;
myLength=iLength-1;
myIsAllocated=Standard_True;
myStart = (void*) p;
} }
//======================================================================= //=======================================================================
//function : Append //function : Append
@ -114,6 +114,7 @@
Destroy(); Destroy();
myFactLength=iLengthToAllocate; myFactLength=iLengthToAllocate;
myIsAllocated=Standard_True; myIsAllocated=Standard_True;
myStart = (void*) p; myStart = (void*) p;
@ -130,8 +131,8 @@
//function : IsInvalidIndex //function : IsInvalidIndex
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean BOPTColStd_CArray1::IsInvalidIndex Standard_Boolean BOPTColStd_CArray1::IsInvalidIndex
(const Standard_Integer anInd)const (const Standard_Integer anInd)const
{ {
Standard_Boolean aFlag; Standard_Boolean aFlag;
Standard_Integer anIndx=anInd-1; Standard_Integer anIndx=anInd-1;
@ -142,7 +143,7 @@
//function : Destroy //function : Destroy
//purpose : //purpose :
//======================================================================= //=======================================================================
void BOPTColStd_CArray1::Destroy() void BOPTColStd_CArray1::Destroy()
{ {
if (myIsAllocated) { if (myIsAllocated) {
delete [] (Array1Item *)myStart; delete [] (Array1Item *)myStart;
@ -151,13 +152,13 @@
myLength=0; myLength=0;
myStart=NULL; myStart=NULL;
} }
//myStart=NULL;
} }
//======================================================================= //=======================================================================
//function : Length //function : Length
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer BOPTColStd_CArray1::Length() const Standard_Integer BOPTColStd_CArray1::Length() const
{ {
return myLength; return myLength;
} }
@ -165,7 +166,7 @@
//function : Extent //function : Extent
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer BOPTColStd_CArray1::Extent() const Standard_Integer BOPTColStd_CArray1::Extent() const
{ {
return myLength; return myLength;
} }
@ -173,7 +174,7 @@
//function : FactLength //function : FactLength
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer BOPTColStd_CArray1::FactLength() const Standard_Integer BOPTColStd_CArray1::FactLength() const
{ {
return myFactLength; return myFactLength;
} }
@ -189,16 +190,17 @@
//function : SetBlockLength //function : SetBlockLength
//purpose : //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; myBlockLength=aBL;
}
} }
//======================================================================= //=======================================================================
//function : Value //function : Value
//purpose : //purpose :
//======================================================================= //=======================================================================
const Array1Item& BOPTColStd_CArray1::Value const Array1Item& BOPTColStd_CArray1::Value
(const Standard_Integer Index) const (const Standard_Integer Index) const
{ {
if (IsInvalidIndex(Index)) { if (IsInvalidIndex(Index)) {
@ -210,7 +212,7 @@
//function : ChangeValue //function : ChangeValue
//purpose : //purpose :
//======================================================================= //=======================================================================
Array1Item& BOPTColStd_CArray1::ChangeValue Array1Item& BOPTColStd_CArray1::ChangeValue
(const Standard_Integer Index) (const Standard_Integer Index)
{ {
if (IsInvalidIndex(Index)) { if (IsInvalidIndex(Index)) {
@ -218,3 +220,53 @@
} }
return ((Array1Item *)myStart)[Index-1]; 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);
}
*/

View File

@ -58,6 +58,7 @@
#include <OSD_Chronometer.hxx> #include <OSD_Chronometer.hxx>
#include <BRepTools.hxx> #include <BRepTools.hxx>
#include <BOPTColStd_CArray1OfInteger.hxx>
static static
Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
@ -74,6 +75,12 @@ static
void PrintState (Draw_Interpretor& aDI, void PrintState (Draw_Interpretor& aDI,
const TopAbs_State& aState); 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 bhaspc (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer baddve (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** ); 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 bclassify (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer b2dclassify (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 bhole (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer bxhole (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 //function : LowCommands
//purpose : //purpose :
@ -120,10 +124,8 @@ static Standard_Integer bxhole (Draw_Interpretor& , Standard_Integer , con
__FILE__, bclassify , g); __FILE__, bclassify , g);
theCommands.Add("b2dclassify" , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ", theCommands.Add("b2dclassify" , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
__FILE__, b2dclassify , g); __FILE__, b2dclassify , g);
//modified by NIZNHY-PKV Mon May 29 11:45:33 2006f
theCommands.Add("bhole" , "Use bhole" , __FILE__, bhole , g); theCommands.Add("bhole" , "Use bhole" , __FILE__, bhole , g);
theCommands.Add("bxhole" , "Use bxhole" , __FILE__, bxhole , 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 //function : bhole
//purpose : //purpose :
@ -901,4 +902,3 @@ Standard_Integer bxhole (Draw_Interpretor& aDI,
// //
return 0; return 0;
} }
//modified by NIZNHY-PKV Mon May 29 11:40:31 2006t

View File

@ -5256,6 +5256,56 @@ Standard_Integer OCC22736 (Draw_Interpretor& di, Standard_Integer argc, const ch
return 0; 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) { void QAOCC::Commands(Draw_Interpretor& theCommands) {
const char *group = "QAOCC"; 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("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("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("OCC22744", "OCC22744", __FILE__, OCC22744, group);
theCommands.Add("bcarray", "bcarray", __FILE__, bcarray, group);
return; return;
} }