Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
NCollection_AccAllocator Class Reference

Class NCollection_AccAllocator - accumulating memory allocator. This class allocates memory on request returning the pointer to the allocated space. The allocation units are grouped in blocks requested from the system as required. This memory is returned to the system when all allocations in a block are freed. More...

#include <NCollection_AccAllocator.hxx>

Inheritance diagram for NCollection_AccAllocator:
Inheritance graph
[legend]

Data Structures

class  AlignedPtr
 A pointer aligned to a 4 byte boundary. More...
 
class  AlignedSize
 Size value aligned to a 4 byte boundary. More...
 
struct  Block
 Descriptor of a block. More...
 
class  Hasher
 Key hasher. More...
 
struct  Key
 A key for the map of blocks. More...
 

Public Member Functions

 NCollection_AccAllocator (const size_t theBlockSize=DefaultBlockSize)
 Constructor.
 
 ~NCollection_AccAllocator () override
 Destructor.
 
voidAllocate (const size_t theSize) override
 Allocate memory with given size.
 
voidAllocateOptimal (const size_t theSize) override
 Allocate memory with given size.
 
void Free (void *theAddress) override
 Free a previously allocated memory; memory is returned to the OS when all allocations in some block are freed.
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor.
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing.
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter.
 
virtual ~Standard_Transient ()=default
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
bool IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
bool IsInstance (const char *const theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
bool 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.
 
bool IsKind (const char *const 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.
 
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.
 
int GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object. Uses relaxed memory ordering since incrementing only requires atomicity, not synchronization with other memory operations.
 
int DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value. Uses release ordering for the decrement to ensure all writes to the object are visible before the count reaches zero. An acquire fence is added only when the count reaches zero, ensuring proper synchronization before deletion. This is more efficient than using acq_rel for every decrement.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Static Public Attributes

static constexpr size_t Align = 4
 Alignment of all allocated objects: 4 bytes.
 
static constexpr size_t DefaultBlockSize = 24600
 Default block size.
 
static constexpr int MaxLookupBlocks = 16
 Number of last blocks to check for free space.
 

Protected Member Functions

Key getKey (void *const theAddress) const noexcept
 Calculate a key for the data map basing on the given address.
 
BlockfindBlock (void *const theAddress, Key &theKey) noexcept
 Find a block that the given allocation unit belongs to.
 
BlockallocateNewBlock (const size_t theSize)
 Allocate a new block and return a pointer to it.
 
- Protected Member Functions inherited from NCollection_BaseAllocator
 NCollection_BaseAllocator () noexcept
 Constructor - prohibited.
 

Protected Attributes

AlignedSize myBlockSize
 
BlockmypLastBlock
 
NCollection_DataMap< Key, Block, HashermyBlocks
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 
- Static Public Member Functions inherited from NCollection_BaseAllocator
static const occ::handle< NCollection_BaseAllocator > & CommonBaseAllocator ()
 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.
 
- Static Public Member Functions inherited from Standard_Transient
static constexpr const charget_type_name ()
 Returns a type descriptor about this object.
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class.
 

Detailed Description

Class NCollection_AccAllocator - accumulating memory allocator. This class allocates memory on request returning the pointer to the allocated space. The allocation units are grouped in blocks requested from the system as required. This memory is returned to the system when all allocations in a block are freed.

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

By comparison with NCollection_IncAllocator, this class requires some more additional memory and a little more time for allocation and deallocation. Memory overhead for NCollection_IncAllocator is 12 bytes per block; average memory overhead for NCollection_AccAllocator is 28 bytes per block.

All pointers returned by Allocate() are aligned to 4 byte boundaries. To define the sizeof memory blocks requested from the OS, use the parameter of the constructor (measured in bytes).

Constructor & Destructor Documentation

◆ NCollection_AccAllocator()

NCollection_AccAllocator::NCollection_AccAllocator ( const size_t theBlockSize = DefaultBlockSize)

Constructor.

◆ ~NCollection_AccAllocator()

NCollection_AccAllocator::~NCollection_AccAllocator ( )
override

Destructor.

Member Function Documentation

◆ Allocate()

void * NCollection_AccAllocator::Allocate ( const size_t theSize)
overridevirtual

Allocate memory with given size.

Reimplemented from NCollection_BaseAllocator.

◆ allocateNewBlock()

Block * NCollection_AccAllocator::allocateNewBlock ( const size_t theSize)
protected

Allocate a new block and return a pointer to it.

◆ AllocateOptimal()

void * NCollection_AccAllocator::AllocateOptimal ( const size_t theSize)
inlineoverridevirtual

Allocate memory with given size.

Reimplemented from NCollection_BaseAllocator.

◆ findBlock()

Block * NCollection_AccAllocator::findBlock ( void *const theAddress,
Key & theKey )
protectednoexcept

Find a block that the given allocation unit belongs to.

◆ Free()

void NCollection_AccAllocator::Free ( void * theAddress)
overridevirtual

Free a previously allocated memory; memory is returned to the OS when all allocations in some block are freed.

Reimplemented from NCollection_BaseAllocator.

◆ getKey()

Key NCollection_AccAllocator::getKey ( void *const theAddress) const
inlineprotectednoexcept

Calculate a key for the data map basing on the given address.

Field Documentation

◆ Align

constexpr size_t NCollection_AccAllocator::Align = 4
staticconstexpr

Alignment of all allocated objects: 4 bytes.

◆ DefaultBlockSize

constexpr size_t NCollection_AccAllocator::DefaultBlockSize = 24600
staticconstexpr

Default block size.

◆ MaxLookupBlocks

constexpr int NCollection_AccAllocator::MaxLookupBlocks = 16
staticconstexpr

Number of last blocks to check for free space.

◆ myBlocks

NCollection_DataMap<Key, Block, Hasher> NCollection_AccAllocator::myBlocks
protected

◆ myBlockSize

AlignedSize NCollection_AccAllocator::myBlockSize
protected

◆ mypLastBlock

Block* NCollection_AccAllocator::mypLastBlock
protected

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