![]() |
ezEngine Release 26.3
|
Generic identifier template that combines instance indexing with generation counting for safe object references. More...
#include <Id.h>
Public Types | |
| enum | { STORAGE_SIZE = ((InstanceIndexBits + GenerationBits - 1) / 8) + 1 } |
| using | StorageType = typename ezSizeToType< STORAGE_SIZE >::Type |
Public Member Functions | |
| EZ_DECLARE_ID_TYPE (ezGenericId, InstanceIndexBits, GenerationBits) | |
| EZ_ALWAYS_INLINE | ezGenericId (StorageType instanceIndex, StorageType generation) |
Public Attributes | ||
| union { | ||
| StorageType m_Data | ||
| struct { | ||
| StorageType m_InstanceIndex: InstanceIndexBits | ||
| StorageType m_Generation: GenerationBits | ||
| } | ||
| }; | ||
Generic identifier template that combines instance indexing with generation counting for safe object references.
This ID system solves the "dangling pointer" problem for object management by using a two-part identifier:
When an object is destroyed, its generation counter is incremented. Any existing IDs with the old generation value become automatically invalid, preventing access to the new object that might occupy the same index.
Benefits:
Template parameters allow customization of the index space vs. generation granularity:
Typical configurations: