Documentation
¶
Index ¶
Constants ¶
const SlabSize = 1024 * 1024
SlabSize is the size of each memory block (1MB)
Variables ¶
This section is empty.
Functions ¶
func AllocStruct ¶
func AllocStruct[T any](a *SlabAllocator) *T
AllocStruct allocates space for a struct of type T and returns a pointer to it. T must be a plain old data type (no pointers that need GC scanning ideally, though Go GC will scan it if typed correctly, but this is for optimization).
Types ¶
type SlabAllocator ¶
type SlabAllocator struct {
// contains filtered or unexported fields
}
SlabAllocator manages memory in large chunks (slabs) to reduce GC pressure. It is optimized for append-only or long-lived structures like HNSW graphs.
func NewSlabAllocator ¶
func NewSlabAllocator() *SlabAllocator
NewSlabAllocator creates a new allocator.
func (*SlabAllocator) Alloc ¶
func (a *SlabAllocator) Alloc(n int) []byte
Alloc allocates a slice of size n bytes. The returned slice is valid until Reset() is called. NOT thread-safe for allocation; usually protected by structure's lock (e.g. HNSW lock).
func (*SlabAllocator) Reset ¶
func (a *SlabAllocator) Reset()
Reset frees all allocated memory by dropping references to slabs. This allows GC to reclaim huge chunks at once.
func (*SlabAllocator) TotalAllocated ¶
func (a *SlabAllocator) TotalAllocated() int64
TotalAllocated returns bytes allocated by this arena.