Open CASCADE Technology  7.2.0
Data Structures | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
NCollection_IncAllocator Class Reference

#include <NCollection_IncAllocator.hxx>

Inheritance diagram for NCollection_IncAllocator:
Inheritance graph
[legend]

Data Structures

struct  IBlock
 

Public Types

typedef void * aligned_t
 
- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 

Public Member Functions

 NCollection_IncAllocator (const size_t theBlockSize=DefaultBlockSize)
 Constructor. More...
 
virtual void * Allocate (const size_t size) override
 Allocate memory with given size. Returns NULL on failure. More...
 
virtual void Free (void *anAddress) override
 Free a previously allocated memory. Does nothing. More...
 
size_t GetMemSize () const
 Diagnostic method, returns the total allocated size. More...
 
 ~NCollection_IncAllocator ()
 Destructor (calls Clean() internally) More...
 
void * Reallocate (void *anAddress, const size_t oldSize, const size_t newSize)
 Reallocation: it is always allowed but is only efficient with the last allocated item. More...
 
void Reset (const Standard_Boolean doReleaseMem=Standard_True)
 Re-initialize the allocator so that the next Allocate call should start allocating in the very begining as though the allocator is just constructed. Warning: make sure that all previously allocated data are no more used in your code! More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Static Public Attributes

static const size_t DefaultBlockSize = 24600
 

Protected Member Functions

void Clean ()
 Flush all previously allocated data. All pointers returned by Allocate() become invalid – be very careful with this. More...
 
void * allocateNewBlock (const size_t cSize)
 Allocate a new block and return a pointer to it ** only for internal usage **. More...
 
- Protected Member Functions inherited from NCollection_BaseAllocator
 NCollection_BaseAllocator (void)
 Constructor - prohibited. More...
 

Protected Attributes

IBlockmyFirstBlock
 
size_t mySize
 
size_t myMemSize
 

Additional Inherited Members

- Static Public Member Functions inherited from NCollection_BaseAllocator
static const Handle< NCollection_BaseAllocator > & CommonBaseAllocator (void)
 CommonBaseAllocator This method is designed to have the only one BaseAllocator (to avoid useless copying of collections). However one can use operator new to create more BaseAllocators, but it is injurious. More...
 
static void StandardCallBack (const Standard_Boolean theIsAlloc, const Standard_Address theStorage, const Standard_Size theRoundSize, const Standard_Size theSize)
 Callback function to register alloc/free calls. More...
 
static void PrintMemUsageStatistics ()
 Prints memory usage statistics cumulated by StandardCallBack. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Detailed Description

Class NCollection_IncAllocator - incremental memory allocator. This class allocates memory on request returning the pointer to an allocated block. This memory is never returned to the system until the allocator is destroyed.

By comparison with the standard new() and malloc() calls, this method is faster and consumes very small additional memory to maintain the heap.

All pointers returned by Allocate() are aligned to the size of the data type "aligned_t". To modify the size of memory blocks requested from the OS, use the parameter of the constructor (measured in bytes); if this parameter is smaller than 25 bytes on 32bit or 49 bytes on 64bit, the block size will be the default 24 kbytes

Member Typedef Documentation

◆ aligned_t

Constructor & Destructor Documentation

◆ NCollection_IncAllocator()

NCollection_IncAllocator::NCollection_IncAllocator ( const size_t  theBlockSize = DefaultBlockSize)

Constructor.

◆ ~NCollection_IncAllocator()

NCollection_IncAllocator::~NCollection_IncAllocator ( )

Destructor (calls Clean() internally)

Member Function Documentation

◆ Allocate()

virtual void* NCollection_IncAllocator::Allocate ( const size_t  size)
overridevirtual

Allocate memory with given size. Returns NULL on failure.

Reimplemented from NCollection_BaseAllocator.

◆ allocateNewBlock()

void* NCollection_IncAllocator::allocateNewBlock ( const size_t  cSize)
protected

Allocate a new block and return a pointer to it ** only for internal usage **.

◆ Clean()

void NCollection_IncAllocator::Clean ( )
protected

Flush all previously allocated data. All pointers returned by Allocate() become invalid – be very careful with this.

◆ Free()

virtual void NCollection_IncAllocator::Free ( void *  anAddress)
overridevirtual

Free a previously allocated memory. Does nothing.

Reimplemented from NCollection_BaseAllocator.

◆ GetMemSize()

size_t NCollection_IncAllocator::GetMemSize ( ) const

Diagnostic method, returns the total allocated size.

◆ Reallocate()

void* NCollection_IncAllocator::Reallocate ( void *  anAddress,
const size_t  oldSize,
const size_t  newSize 
)

Reallocation: it is always allowed but is only efficient with the last allocated item.

◆ Reset()

void NCollection_IncAllocator::Reset ( const Standard_Boolean  doReleaseMem = Standard_True)

Re-initialize the allocator so that the next Allocate call should start allocating in the very begining as though the allocator is just constructed. Warning: make sure that all previously allocated data are no more used in your code!

Parameters
doReleaseMemTrue - release all previously allocated memory, False - preserve it for future allocations.

Field Documentation

◆ DefaultBlockSize

const size_t NCollection_IncAllocator::DefaultBlockSize = 24600
static

◆ myFirstBlock

IBlock* NCollection_IncAllocator::myFirstBlock
protected

◆ myMemSize

size_t NCollection_IncAllocator::myMemSize
protected

◆ mySize

size_t NCollection_IncAllocator::mySize
protected

The documentation for this class was generated from the following file: