ZXFoundation™ 26h2
Loading...
Searching...
No Matches
lib::id_allocator< MaxIds > Class Template Referenceexport

Fixed-capacity SMP-safe ID allocator backed by a bitmap. More...

Public Member Functions

auto alloc () noexcept -> std::optional< u32 >
 Allocate the lowest available ID.
auto count () const noexcept -> u32
 Number of currently allocated IDs.
auto free (u32 id) noexcept -> void
 Free a previously allocated ID.
auto is_allocated (u32 id) const noexcept -> bool
 Check if an ID is currently allocated.
auto reserve (u32 n) noexcept -> void
 Reserve IDs [0, n). These will never be returned by alloc().

Static Public Attributes

static constexpr u32 capacity = static_cast<u32>(MaxIds)
 Maximum capacity.

Detailed Description

template<usize MaxIds>
class lib::id_allocator< MaxIds >

Fixed-capacity SMP-safe ID allocator backed by a bitmap.

Template Parameters
MaxIdsMaximum number of IDs (0 to MaxIds-1).

Member Function Documentation

◆ alloc()

template<usize MaxIds>
auto lib::id_allocator< MaxIds >::alloc ( ) ->std::optional< u32 >
inlinenodiscardexportnoexcept

Allocate the lowest available ID.

Returns
The allocated ID, or nullopt if all IDs exhausted.

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