Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Slab ¶
type Slab[T any] struct { // contains filtered or unexported fields }
Slab is a simple slab allocator for objects of type T. It maintains an internal buffer of pre-allocated objects and allows for efficient allocation and resetting. If the internal buffer is exhausted, it falls back to heap allocation.
func NewSlab ¶
NewSlab creates a new slab with the given capacity and clear function (a function that releases internal type resources; use nil if not needed).
func (*Slab[T]) Alloc ¶
func (s *Slab[T]) Alloc() *T
Alloc returns a pointer to an object of type T. It first tries to allocate from the slab's internal buffer, and if that is exhausted, it falls back to heap allocation.
func (*Slab[T]) Reset ¶
func (s *Slab[T]) Reset()
Reset clears the slab, making all previously allocated objects available for reuse. If a clear function was provided, it will be called on each object in the slab before resetting.
type SliceSlab ¶
type SliceSlab[T any] struct { // contains filtered or unexported fields }
SliceSlab is a simple slab allocator for slices. It preallocates a number of slices with a fixed capacity and returns them on demand. If the requested capacity exceeds the preallocated capacity or if all preallocated slices are used, it falls back to allocating a new slice on the heap.
func NewSliceSlab ¶
NewSliceSlab creates a new SliceSlab with the given number of slices (size) and capacity for each slice (cap).
func (*SliceSlab[T]) Alloc ¶
Alloc returns a slice of type T with the requested minimum capacity. It first tries to allocate from the slab's internal buffer, and if that is exhausted or if the requested capacity exceeds the preallocated capacity, it falls back to heap allocation. If sized is true, the returned slice will have a length equal to the requested capacity; otherwise, it will have a length of 0 and the requested capacity.
func (*SliceSlab[T]) Reset ¶
func (s *SliceSlab[T]) Reset()
Reset clears the slab, making all previously allocated slices available for reuse.