Skip to content

EntropyEngine::Core::SlotPool

Slot-based pool with generation-based handle validation. More…

#include <SlotPool.h>

Name
structSlot
Internal slot structure combining generation tracking with user data.
structAllocResult
Result of allocate() containing slot index and data reference.
Name
template <typename T >
void
stamp(T & obj, uint32_t index)
Stamps an EntropyObject with this pool’s identity.
template <typename T >
void
release(T & obj, uint32_t index)
Releases a slot back to the pool.
template <typename T >
bool
isValid(const T * obj, uint32_t index) const
Validates an object against its expected slot.
boolisActive(uint32_t index) const
Checks if a slot is currently active (allocated).
template <typename T >
const SlotData *
getIfValid(const T * obj) const
Validates an object and returns its slot data if valid.
uint32_tgeneration(uint32_t index) const
Gets a slot’s current generation.
size_tfreeCount() const
template <typename Fn >
void
forEachActive(Fn && fn)
Iterates over all active slots.
template <typename Fn >
void
forEachActive(Fn && fn) const
Iterates over all active slots (const).
size_tcapacity() const
SlotData &at(uint32_t index)
Gets a slot’s data by index (unsafe - no validation).
const SlotData &at(uint32_t index) const
Gets a slot’s data by index (const, unsafe - no validation).
std::optional< AllocResult >allocate()
Allocates a slot from the pool.
size_tactiveCount() const
SlotPool(size_t capacity)
Constructs a pool with the given capacity.
template <typename SlotData >
class EntropyEngine::Core::SlotPool;

Slot-based pool with generation-based handle validation.

Template Parameters:

  • SlotData User-defined data stored in each slot (will be default-constructed)

Thread Safety:

  • All public methods are thread-safe (protected by internal mutex)
  • SlotData must be safe to access under the returned lock guard
template <typename T >
inline void stamp(
T & obj,
uint32_t index
)

Stamps an EntropyObject with this pool’s identity.

Parameters:

Template Parameters:

  • T EntropyObject-derived type

Call this after allocate() to establish the object’s handle identity.

template <typename T >
inline void release(
T & obj,
uint32_t index
)

Releases a slot back to the pool.

Parameters:

  • obj Object to release
  • index Slot index

Template Parameters:

  • T EntropyObject-derived type

Clears the object’s handle stamp and increments the slot’s generation to invalidate any stale references.

template <typename T >
inline bool isValid(
const T * obj,
uint32_t index
) const

Validates an object against its expected slot.

Parameters:

  • obj Object to validate (may be null)
  • index Expected slot index

Template Parameters:

  • T EntropyObject-derived type

Return: true if object is valid for this slot

inline bool isActive(
uint32_t index
) const

Checks if a slot is currently active (allocated).

Parameters:

Return: true if slot is active

template <typename T >
inline const SlotData * getIfValid(
const T * obj
) const

Validates an object and returns its slot data if valid.

Parameters:

  • obj Object to validate

Template Parameters:

  • T EntropyObject-derived type

Return: Pointer to slot data, or nullptr if invalid

Convenience method that combines validation with data access.

inline uint32_t generation(
uint32_t index
) const

Gets a slot’s current generation.

Parameters:

Return: Current generation value

inline size_t freeCount() const
template <typename Fn >
inline void forEachActive(
Fn && fn
)

Iterates over all active slots.

Parameters:

  • fn Callback receiving (index, SlotData&) for each active slot
template <typename Fn >
inline void forEachActive(
Fn && fn
) const

Iterates over all active slots (const).

inline size_t capacity() const
inline SlotData & at(
uint32_t index
)

Gets a slot’s data by index (unsafe - no validation).

Parameters:

Return: Reference to slot data

Use isValid() first, or prefer getIfValid() for safe access.

inline const SlotData & at(
uint32_t index
) const

Gets a slot’s data by index (const, unsafe - no validation).

inline std::optional< AllocResult > allocate()

Allocates a slot from the pool.

Return: Optional containing (index, data reference), or nullopt if pool is full

inline size_t activeCount() const
inline explicit SlotPool(
size_t capacity
)

Constructs a pool with the given capacity.

Parameters:

  • capacity Maximum number of slots

Slots are default-constructed immediately. Use init() for lazy initialization if SlotData requires external dependencies.


Updated on 2026-01-26 at 16:50:32 -0500