SlotAllocator
Hands out the same handles as SlotMap, for values kept in your own arrays. Each handle names a slot, and
SlotAllocator:SlotOf gives a live handle’s slot, so arrays indexed by slot hold the values. A slot is reused
32,767 times, then retired, so a handle to a freed slot never matches again.
local Slots = Collections.SlotAllocator.new()local Names = {}local Handle, Slot = Slots:Allocate()Names[Slot] = "goblin"Slots:Free(Handle)print(Slots:IsAlive(Handle), Slots:SlotOf(Handle)) -- false nilSummary
Section titled “Summary”| Member | Description |
|---|---|
.PackHandle() |
Builds a handle from a slot and a generation, as Collections.PackHandle does. |
.UnpackHandle() |
Splits a handle into its slot and generation, as Collections.UnpackHandle does. |
.new() |
Creates an empty allocator. |
:Allocate() |
Takes the lowest free slot and returns a handle to it. |
:IsAlive() |
Whether Handle’s slot is still allocated to it. |
:SlotOf() |
Returns a live Handle’s slot, or nil once it is freed. |
:Free() |
Frees Handle’s slot, and returns false if Handle was not live. |
:Count() |
How many handles are live. |
:Capacity() |
How many slots fit before it next grows. |
:Clear() |
Frees every slot at once. |
Config |
Settings for SlotAllocator.new. |
Functions
Section titled “Functions”PackHandle
Section titled “PackHandle”function SlotAllocator.PackHandle(Slot: number, Generation: number): numberBuilds a handle from a slot and a generation, as Collections.PackHandle does.
UnpackHandle
Section titled “UnpackHandle”function SlotAllocator.UnpackHandle(Handle: number): (number, number)Splits a handle into its slot and generation, as Collections.UnpackHandle does.
function SlotAllocator.new(Config: Config?): SlotAllocatorCreates an empty allocator.
Methods
Section titled “Methods”Allocate
Section titled “Allocate”function SlotAllocator:Allocate(): (number, number)Takes the lowest free slot and returns a handle to it.
| Returns | Description |
|---|---|
number |
the handle |
number |
its slot |
IsAlive
Section titled “IsAlive”function SlotAllocator:IsAlive(Handle: number): booleanWhether Handle’s slot is still allocated to it.
SlotOf
Section titled “SlotOf”function SlotAllocator:SlotOf(Handle: number): number?Returns a live Handle’s slot, or nil once it is freed.
function SlotAllocator:Free(Handle: number): booleanFrees Handle’s slot, and returns false if Handle was not live.
function SlotAllocator:Count(): numberHow many handles are live.
Capacity
Section titled “Capacity”function SlotAllocator:Capacity(): numberHow many slots fit before it next grows.
function SlotAllocator:Clear()Frees every slot at once. Every handle given out so far stops matching.
Config
Section titled “Config”export type Config = {
InitialCapacity: number?,
OnGrow: ((Old: number, New: number) -> ())?,
}Settings for SlotAllocator.new.
| Field | Type | Description |
|---|---|---|
InitialCapacity |
number? |
slots to make room for up front, 8 by default, rounded up to a power of two |
OnGrow |
((Old: number, New: number) -> ())? |
called with the old and new capacity whenever it grows |
© 2026 PRMS Developer