ezEngine Release 26.3
Loading...
Searching...
No Matches
ezBlockStorage< T, BlockSizeInByte, StorageType > Class Template Reference

High-performance container for objects with pluggable storage strategies. More...

#include <BlockStorage.h>

Classes

class  ConstIterator
 
class  Iterator
 

Public Member Functions

 ezBlockStorage (ezLargeBlockAllocator< BlockSizeInByte > *pBlockAllocator, ezAllocator *pAllocator)
 
void Clear ()
 Removes all objects and deallocates all blocks.
 
T * Create ()
 Creates a new object and returns a pointer to it.
 
void Delete (T *pObject)
 Deletes the specified object.
 
void Delete (T *pObject, T *&out_pMovedObject)
 Deletes the specified object and reports any moved object.
 
ezUInt32 GetCount () const
 Returns the total number of objects currently stored.
 
Iterator GetIterator (ezUInt32 uiStartIndex=0, ezUInt32 uiCount=ezInvalidIndex)
 Returns an iterator for traversing objects in a specified range.
 
ConstIterator GetIterator (ezUInt32 uiStartIndex=0, ezUInt32 uiCount=ezInvalidIndex) const
 Returns a const iterator for traversing objects in a specified range.
 

Detailed Description

template<typename T, ezUInt32 BlockSizeInByte, ezBlockStorageType::Enum StorageType>
class ezBlockStorage< T, BlockSizeInByte, StorageType >

High-performance container for objects with pluggable storage strategies.

This container manages objects in blocks of memory, using different strategies for handling gaps when objects are removed. It's designed for scenarios where you need fast allocation and deallocation of many objects, with the choice between compact memory layout or stable object addressing.

Storage strategies:

  • Compact: Moves the last element to fill gaps when objects are deleted, maintaining contiguous memory but invalidating iterators and pointers to moved objects
  • FreeList: Uses a free list to reuse deleted slots, preserving object positions but potentially creating memory fragmentation

Member Function Documentation

◆ Create()

template<typename T , ezUInt32 BlockSize, ezBlockStorageType::Enum StorageType>
T * ezBlockStorage< T, BlockSize, StorageType >::Create ( )

Creates a new object and returns a pointer to it.

The object is default-constructed. Returns nullptr if allocation fails.

◆ Delete()

template<typename T , ezUInt32 BlockSize, ezBlockStorageType::Enum StorageType>
void ezBlockStorage< T, BlockSize, StorageType >::Delete ( T *  pObject,
T *&  out_pMovedObject 
)

Deletes the specified object and reports any moved object.

For Compact storage, if another object is moved to fill the gap, out_pMovedObject will point to the moved object's new location. For FreeList storage, out_pMovedObject is always set to nullptr.


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