1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0024489: Avoid type casts in call to Standard::Free()

Method Standard::Free() is converted to template, so that pointer is nullified using its proper type.
Unnecessary type cases in calls to Standard::Free(), Standard::Reallocate(), and NCollection_BaseAllocator::Free() eliminated throughout OCCT code.
This commit is contained in:
abv
2014-01-09 11:56:20 +04:00
committed by bugmaster
parent b24ac89262
commit 547702a15d
28 changed files with 105 additions and 123 deletions

View File

@@ -133,11 +133,13 @@ is
---Purpose: Allocates memory blocks
-- aSize - bytes to allocate
Free (aStorage:in out Address from Standard);
---Purpose: Deallocates memory blocks
-- aStorage - previously allocated memory block to be freed
Free (aStorage: Address from Standard);
---Purpose: Deallocates memory blocks
-- aStorage - previously allocated memory block to be freed
Reallocate(aStorage: in out Address from Standard;
---C++: alias "template <typename T> static inline void Free (T*& thePtr) { Free ((void*)thePtr); thePtr = 0; }"
Reallocate(aStorage: Address from Standard;
aNewSize: Size from Standard)
returns Address from Standard;
---Purpose: Reallocates memory blocks

View File

@@ -183,13 +183,13 @@ Standard_Address Standard::Allocate(const Standard_Size size)
}
//=======================================================================
//function : Free
//function : FreeAddress
//purpose :
//=======================================================================
void Standard::Free(Standard_Address& aStorage)
void Standard::Free (Standard_Address theStorage)
{
GetMMgr()->Free(aStorage);
GetMMgr()->Free(theStorage);
}
//=======================================================================
@@ -197,10 +197,10 @@ void Standard::Free(Standard_Address& aStorage)
//purpose :
//=======================================================================
Standard_Address Standard::Reallocate(Standard_Address& aStorage,
const Standard_Size newSize)
Standard_Address Standard::Reallocate (Standard_Address theStorage,
const Standard_Size theSize)
{
return GetMMgr()->Reallocate(aStorage, newSize);
return GetMMgr()->Reallocate (theStorage, theSize);
}
//=======================================================================

View File

@@ -61,7 +61,7 @@
} \
void operator delete (void* theAddress) \
{ \
Standard::Free ((Standard_Address&)theAddress); \
Standard::Free (theAddress); \
} \
DEFINE_STANDARD_ALLOC_ARRAY \
DEFINE_STANDARD_ALLOC_PLACEMENT

View File

@@ -475,7 +475,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
//purpose :
//=======================================================================
void Standard_MMgrOpt::Free(Standard_Address& theStorage)
void Standard_MMgrOpt::Free(Standard_Address theStorage)
{
// safely return if attempt to free null pointer
if ( ! theStorage )
@@ -510,8 +510,6 @@ void Standard_MMgrOpt::Free(Standard_Address& theStorage)
// otherwise, we have block of big size which shall be simply released
else
FreeMemory (aBlock, RoundSize);
theStorage = NULL;
}
//=======================================================================
@@ -704,7 +702,7 @@ void Standard_MMgrOpt::FreePools()
//purpose :
//=======================================================================
Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address& theStorage,
Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address theStorage,
const Standard_Size theNewSize)
{
// if theStorage == NULL, just allocate new memory block
@@ -732,7 +730,6 @@ Standard_Address Standard_MMgrOpt::Reallocate(Standard_Address& theStorage,
if ( myClear )
memset(((char*)newStorage) + OldSize, 0, theNewSize-OldSize);
}
theStorage = NULL;
return newStorage;
}

View File

@@ -97,15 +97,15 @@ class Standard_MMgrOpt : public Standard_MMgrRoot
//! Allocate aSize bytes; see class description above
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate previously allocated aPtr to a new size; aPtr is nullified.
//! Reallocate previously allocated aPtr to a new size; new address is returned.
//! In case that aPtr is null, the function behaves exactly as Allocate.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr,
const Standard_Size aSize);
Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size theSize);
//! Free previously allocated block; aPtr is nullified.
//! Free previously allocated block.
//! Note that block can not all blocks are released to the OS by this
//! method (see class description)
Standard_EXPORT virtual void Free(Standard_Address& aPtr);
Standard_EXPORT virtual void Free (Standard_Address thePtr);
//! Release medium-sized blocks of memory in free lists to the system.
//! Returns number of actually freed blocks

View File

@@ -50,10 +50,9 @@ Standard_Address Standard_MMgrRaw::Allocate(const Standard_Size aSize)
//purpose :
//=======================================================================
void Standard_MMgrRaw::Free(Standard_Address& aStorage)
void Standard_MMgrRaw::Free(Standard_Address theStorage)
{
free(aStorage);
aStorage=NULL;
free(theStorage);
}
//=======================================================================
@@ -61,18 +60,17 @@ void Standard_MMgrRaw::Free(Standard_Address& aStorage)
//purpose :
//=======================================================================
Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address& aStorage,
const Standard_Size newSize)
Standard_Address Standard_MMgrRaw::Reallocate(Standard_Address theStorage,
const Standard_Size theSize)
{
// the size is rounded up to 4 since some OCC classes
// (e.g. TCollection_AsciiString) assume memory to be double word-aligned
const Standard_Size aRoundSize = (newSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)realloc(aStorage, aRoundSize);
const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)realloc(theStorage, aRoundSize);
if ( ! newStorage )
Standard_OutOfMemory::Raise("Standard_MMgrRaw::Reallocate(): realloc failed");
// Note that it is not possible to ensure that additional memory
// allocated by realloc will be cleared (so as to satisfy myClear mode);
// in order to do that we would need using memset...
aStorage = NULL;
return newStorage;
}

View File

@@ -46,12 +46,12 @@ class Standard_MMgrRaw : public Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate aPtr to the size aSize.
//! The pointer aPtr is nullified; new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr,
const Standard_Size aSize);
//! The new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address thePtr,
const Standard_Size theSize);
//! Free allocated memory. The pointer is nullified.
Standard_EXPORT virtual void Free(Standard_Address&);
Standard_EXPORT virtual void Free (Standard_Address thePtr);
protected:
Standard_Boolean myClear; //! Option to nullify allocated memory

View File

@@ -45,13 +45,12 @@ class Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate (const Standard_Size theSize)=0;
//! Reallocate previously allocated memory to contain at least theSize bytes.
//! In case of success, aPtr should be nullified and new pointer returned.
Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address& aPtr,
//! In case of success, new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size theSize)=0;
//! Frees previously allocated memory at specified address.
//! The pointer is nullified.
Standard_EXPORT virtual void Free(Standard_Address& aPtr)=0;
Standard_EXPORT virtual void Free(Standard_Address thePtr)=0;
//! Purge internally cached unused memory blocks (if any)
//! by releasing them to the operating system.

View File

@@ -65,10 +65,9 @@ Standard_Address Standard_MMgrTBBalloc::Allocate(const Standard_Size aSize)
//purpose :
//=======================================================================
void Standard_MMgrTBBalloc::Free(Standard_Address& aStorage)
void Standard_MMgrTBBalloc::Free (Standard_Address theStorage)
{
scalable_free(aStorage);
aStorage=NULL;
scalable_free (theStorage);
}
//=======================================================================
@@ -76,18 +75,17 @@ void Standard_MMgrTBBalloc::Free(Standard_Address& aStorage)
//purpose :
//=======================================================================
Standard_Address Standard_MMgrTBBalloc::Reallocate(Standard_Address& aStorage,
const Standard_Size newSize)
Standard_Address Standard_MMgrTBBalloc::Reallocate (Standard_Address theStorage,
const Standard_Size theSize)
{
// the size is rounded up to 4 since some OCC classes
// (e.g. TCollection_AsciiString) assume memory to be double word-aligned
const Standard_Size aRoundSize = (newSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)scalable_realloc(aStorage, aRoundSize);
const Standard_Size aRoundSize = (theSize + 3) & ~0x3;
Standard_Address newStorage = (Standard_Address)scalable_realloc(theStorage, aRoundSize);
if ( ! newStorage )
Standard_OutOfMemory::Raise("Standard_MMgrTBBalloc::Reallocate(): realloc failed");
// Note that it is not possible to ensure that additional memory
// allocated by realloc will be cleared (so as to satisfy myClear mode);
// in order to do that we would need using memset...
aStorage = NULL;
return newStorage;
}

View File

@@ -47,12 +47,12 @@ class Standard_MMgrTBBalloc : public Standard_MMgrRoot
Standard_EXPORT virtual Standard_Address Allocate(const Standard_Size aSize);
//! Reallocate aPtr to the size aSize.
//! The pointer aPtr is nullified; new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate(Standard_Address& aPtr,
const Standard_Size aSize);
//! The new pointer is returned.
Standard_EXPORT virtual Standard_Address Reallocate (Standard_Address thePtr,
const Standard_Size theSize);
//! Free allocated memory. The pointer is nullified.
Standard_EXPORT virtual void Free(Standard_Address&);
//! Free allocated memory
Standard_EXPORT virtual void Free (Standard_Address thePtr);
protected:
Standard_Boolean myClear; //! Option to nullify allocated memory