UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Chaos::TObjectPool< ObjectType > Class Template Reference

#include <ObjectPool.h>

Public Types

using FObject = ObjectType
 
using FPtr = ObjectType *
 

Public Member Functions

 TObjectPool (int32 InNumPerBlock, int32 InitialBlocks=1)
 
 ~TObjectPool ()
 
 TObjectPool ()=delete
 
 TObjectPool (const TObjectPool &)=delete
 
 TObjectPool (TObjectPool &&)=delete
 
TObjectPooloperator= (const TObjectPool &)=delete
 
TObjectPooloperator= (TObjectPool &&)=delete
 
template<typename... TArgs>
FPtr Alloc (TArgs &&... Args)
 
void Free (FPtr Object)
 
void Reset ()
 
int32 GetNumAllocatedBlocks () const
 
int32 GetNumPerBlock () const
 
int32 GetAllocatedSize () const
 
void ShrinkTo (int32 NumDesiredEmptyBlocks)
 
void ReserveBlocks (int32 NumBlocks)
 
void ReserveItems (int32 NumItems)
 
float GetRatio () const
 
int32 GetNumAllocated () const
 
int32 GetNumFree () const
 
int32 GetCapacity () const
 

Static Public Attributes

static constexpr int32 ItemAlign = alignof(ObjectType)
 

Member Typedef Documentation

◆ FObject

template<typename ObjectType >
using Chaos::TObjectPool< ObjectType >::FObject = ObjectType

◆ FPtr

template<typename ObjectType >
using Chaos::TObjectPool< ObjectType >::FPtr = ObjectType*

Constructor & Destructor Documentation

◆ TObjectPool() [1/4]

template<typename ObjectType >
Chaos::TObjectPool< ObjectType >::TObjectPool ( int32  InNumPerBlock,
int32  InitialBlocks = 1 
)
inlineexplicit

◆ ~TObjectPool()

template<typename ObjectType >
Chaos::TObjectPool< ObjectType >::~TObjectPool ( )
inline

◆ TObjectPool() [2/4]

template<typename ObjectType >
Chaos::TObjectPool< ObjectType >::TObjectPool ( )
delete

◆ TObjectPool() [3/4]

template<typename ObjectType >
Chaos::TObjectPool< ObjectType >::TObjectPool ( const TObjectPool< ObjectType > &  )
delete

◆ TObjectPool() [4/4]

template<typename ObjectType >
Chaos::TObjectPool< ObjectType >::TObjectPool ( TObjectPool< ObjectType > &&  )
delete

Member Function Documentation

◆ Alloc()

template<typename ObjectType >
template<typename... TArgs>
FPtr Chaos::TObjectPool< ObjectType >::Alloc ( TArgs &&...  Args)
inline

Allocate an object from the pool Returns an instance of the object type specified for this pool, either from the next available on the final block, the free list or by allocating a new block to continue providing objects. As this method may defer to the runtime allocator it may sometimes run significantly slower when the pool is exhausted Requires that the object is default constructible

Parameters
Args- ObjectType constructor arguments
Returns
The newly allocated object

◆ Free()

template<typename ObjectType >
void Chaos::TObjectPool< ObjectType >::Free ( FPtr  Object)
inline

Free a single object provided by this pool Takes an object previously allocated in this pool and frees it, accessing the pointer beyond a call to free is an undefined operation and could return garbage or an entirely different object. Avoiding this case is the responsibility of the caller Behavior is also undefined if an object not owned by this pool is passed to Free. Outside of debug this will not be asserted

Parameters
ObjectThe object to free

◆ GetAllocatedSize()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetAllocatedSize ( ) const
inline

Get the allocated (total) size of all blocks in the pool

◆ GetCapacity()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetCapacity ( ) const
inline

Gets the total number of items the pool can currently stor

Returns
The pool capacity

◆ GetNumAllocated()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetNumAllocated ( ) const
inline

Get the number of allocated items.

◆ GetNumAllocatedBlocks()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetNumAllocatedBlocks ( ) const
inline

Get the number of blocks currently allocated in the pool

◆ GetNumFree()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetNumFree ( ) const
inline

Gets the number of free items the pool has remaining

Returns
Number of free items

◆ GetNumPerBlock()

template<typename ObjectType >
int32 Chaos::TObjectPool< ObjectType >::GetNumPerBlock ( ) const
inline

Get the max number of items per block

◆ GetRatio()

template<typename ObjectType >
float Chaos::TObjectPool< ObjectType >::GetRatio ( ) const
inline

Calculates the storage/overhead ratio of the pool. Larger items that have a size close to the alignment boundary will be more efficient on space

Returns
Ratio of storage to overhead

◆ operator=() [1/2]

template<typename ObjectType >
TObjectPool & Chaos::TObjectPool< ObjectType >::operator= ( const TObjectPool< ObjectType > &  )
delete

◆ operator=() [2/2]

template<typename ObjectType >
TObjectPool & Chaos::TObjectPool< ObjectType >::operator= ( TObjectPool< ObjectType > &&  )
delete

◆ ReserveBlocks()

template<typename ObjectType >
void Chaos::TObjectPool< ObjectType >::ReserveBlocks ( int32  NumBlocks)
inline

Makes sure the pool has at least NumBlocks blocks allocated Note: This will never reduce the number of blocks, it will only make sure the pool has at least NumBlocks block allocated, empty or not.

Parameters
NumBlocks- Number of blocks to reserve

◆ ReserveItems()

template<typename ObjectType >
void Chaos::TObjectPool< ObjectType >::ReserveItems ( int32  NumItems)
inline

Makes sure the pool has at least enough blocks allocated to store NumItems Not: This isn't a number of free items, but total items. If a pool has 100 items in it and ReserveItems(100); is called - no action will be taken. This function will also never remove blocks from the pool - only ever increase. To reduce the number of blocks see ShrinkTo

See also
ShrinkTo @Param NumItems - Number of items to reserve

◆ Reset()

template<typename ObjectType >
void Chaos::TObjectPool< ObjectType >::Reset ( )
inline

Reset the whole pool This will invalidate every currently live object from the pool. If a pointer from this pool is dereferenced beyond a call to Reset then it may return garbage, or point to an entirely different object. Avoiding this case is the responsibility of the caller.

◆ ShrinkTo()

template<typename ObjectType >
void Chaos::TObjectPool< ObjectType >::ShrinkTo ( int32  NumDesiredEmptyBlocks)
inline

Shrinks the number of blocks All blocks that are not empty are kept, plus a number of empty blocks specified by the caller Passing zero will remove all empty blocks, leaving any non-empty blocks behind

Parameters
NumDesiredEmptyBlocks- number of empty blocks to keep

Member Data Documentation

◆ ItemAlign

template<typename ObjectType >
constexpr int32 Chaos::TObjectPool< ObjectType >::ItemAlign = alignof(ObjectType)
staticconstexpr

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