AGX Dynamics  2.37.3.2
agx::MemoryPoolOld< T > Class Template Reference

#include <MemoryPool.h>

+ Inheritance diagram for agx::MemoryPoolOld< T >:

Public Member Functions

 MemoryPoolOld (size_t initialSize=0, size_t chunkSize=64)
 
 ~MemoryPoolOld ()
 
T * acquire ()
 
size_t capacity () const
 \ return the total number of elements allocated More...
 
void clear ()
 Clear all memory allocated by this MemoryPoolOld. More...
 
void flush ()
 Return all elements to container. More...
 
void garbageCollect ()
 Free memory not in use. More...
 
int getAutoGarbageCollect () const
 
size_t getChunkSize () const
 
T * getElement ()
 
T * getElement (const T &initializer)
 Get an element of type T, if we have ran out, then allocate a new chunks. More...
 
size_t memUsed () const
 
void setAutoGarbageCollect (int n)
 Set the number of calls to flush which will trigger a call to garbageCollect. More...
 
void setChunkSize (size_t size)
 Set the new size of the chunk. More...
 
void setEnableCallConstructor (bool flag)
 Set to true if the constructor of the elements should be called BEFORE they are returned in getElement();. More...
 
void setMaxAllocationSize (size_t numBytes)
 Set the largest number of bytes a call to new will be. More...
 
size_t size () const
 
- Public Member Functions inherited from agx::ByteAllocator
 ByteAllocator (const char *name="ByteAllocator")
 
 ByteAllocator (const ByteAllocator &other)
 
void * allocateBytes (size_t numBytes, size_t alignment=16)
 Allocate a memory section of specified alignment. More...
 
void deallocateBytes (void *buffer, size_t numBytes)
 Deallocate a section previously allocated using allocateBytes method. More...
 
void deallocateBytes (void *buffer)
 
const char * getName () const
 
ByteAllocator & operator= (const ByteAllocator &other)
 
void setContainer (class Container *)
 

Additional Inherited Members

- Static Public Member Functions inherited from agx::ByteAllocator
static void initMemory (void *data, size_t numBytes, agx::UInt32 pattern)
 
static void * standaloneAllocateBytes (size_t numBytes, size_t alignment=16)
 
static void standaloneDeallocateTypes (void *buffer)
 
- Static Public Attributes inherited from agx::ByteAllocator
static agx::UInt32 allocatedMemoryPattern
 
static agx::UInt32 deallocatedMemoryPattern
 
static bool initMemoryFlag
 

Detailed Description

template<typename T>
class agx::MemoryPoolOld< T >

Definition at line 151 of file MemoryPool.h.

Constructor & Destructor Documentation

◆ MemoryPoolOld()

template<typename T >
agx::MemoryPoolOld< T >::MemoryPoolOld ( size_t  initialSize = 0,
size_t  chunkSize = 64 
)

Definition at line 253 of file MemoryPool.h.

◆ ~MemoryPoolOld()

template<typename T >
agx::MemoryPoolOld< T >::~MemoryPoolOld ( )

Definition at line 264 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::clear().

Member Function Documentation

◆ acquire()

template<typename T >
T* agx::MemoryPoolOld< T >::acquire ( )
inline
Returns
an element of type T from the pool. (same as getElement()

Definition at line 178 of file MemoryPool.h.

References m_capacity.

◆ capacity()

template<typename T >
size_t agx::MemoryPoolOld< T >::capacity ( ) const

\ return the total number of elements allocated

Definition at line 308 of file MemoryPool.h.

Referenced by agx::MemoryPoolOld< T >::getElement(), and agx::MemoryPoolOld< T >::memUsed().

◆ clear()

◆ flush()

template<typename T >
void agx::MemoryPoolOld< T >::flush ( )

Return all elements to container.

Definition at line 428 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::garbageCollect().

◆ garbageCollect()

template<typename T >
void agx::MemoryPoolOld< T >::garbageCollect ( )

Free memory not in use.

Based on the average allocation size (measured at each call to flush), only memory enough to store the average number of elements will be left.

Definition at line 445 of file MemoryPool.h.

References agx::Vector< T, Allocator >::resize(), and agx::Container::size().

Referenced by agx::MemoryPoolOld< T >::flush().

◆ getAutoGarbageCollect()

template<typename T >
int agx::MemoryPoolOld< T >::getAutoGarbageCollect ( ) const
Returns
number of calls to flush which will trigger a garbageCollect

Definition at line 320 of file MemoryPool.h.

◆ getChunkSize()

template<typename T >
size_t agx::MemoryPoolOld< T >::getChunkSize ( ) const
Returns
the current chunkSize

Definition at line 276 of file MemoryPool.h.

◆ getElement() [1/2]

template<typename T >
T * agx::MemoryPoolOld< T >::getElement ( )
inline
Returns
an element of type T from the pool.

Definition at line 326 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::capacity().

◆ getElement() [2/2]

template<typename T >
T * agx::MemoryPoolOld< T >::getElement ( const T &  initializer)
inline

Get an element of type T, if we have ran out, then allocate a new chunks.

Returns
a pointer to an unused element of type T.

Definition at line 350 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::capacity().

◆ memUsed()

template<typename T >
size_t agx::MemoryPoolOld< T >::memUsed ( ) const
Returns
the total memory allocated in the chunks

Definition at line 282 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::capacity().

◆ setAutoGarbageCollect()

template<typename T >
void agx::MemoryPoolOld< T >::setAutoGarbageCollect ( int  n)
inline

Set the number of calls to flush which will trigger a call to garbageCollect.

Parameters
n- Number of calls to flush to get garbageCollect, default: -1 (never)

Definition at line 314 of file MemoryPool.h.

◆ setChunkSize()

template<typename T >
void agx::MemoryPoolOld< T >::setChunkSize ( size_t  size)

Set the new size of the chunk.

Chunks created after this call will have this size.

Definition at line 270 of file MemoryPool.h.

References agx::MemoryPoolOld< T >::size().

◆ setEnableCallConstructor()

template<typename T >
void agx::MemoryPoolOld< T >::setEnableCallConstructor ( bool  flag)
inline

Set to true if the constructor of the elements should be called BEFORE they are returned in getElement();.

Definition at line 295 of file MemoryPool.h.

◆ setMaxAllocationSize()

template<typename T >
void agx::MemoryPoolOld< T >::setMaxAllocationSize ( size_t  numBytes)
inline

Set the largest number of bytes a call to new will be.

Definition at line 301 of file MemoryPool.h.

◆ size()

template<typename T >
size_t agx::MemoryPoolOld< T >::size ( ) const
Returns
number of elements currently in use

Definition at line 289 of file MemoryPool.h.

Referenced by agx::MemoryPoolOld< T >::setChunkSize().


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