memory

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL