Documentation
¶
Overview ¶
Package spill provides a memory-mapped spill buffer for dirty pages.
Index ¶
- Constants
- Variables
- type Bitmap
- type Buffer
- func (b *Buffer) Allocate() ([]byte, *Slot, error)
- func (b *Buffer) AllocatedCount() uint32
- func (b *Buffer) Capacity() uint32
- func (b *Buffer) Clear()
- func (b *Buffer) Close(deleteFile bool) error
- func (b *Buffer) Get(slot *Slot) []byte
- func (b *Buffer) PageSize() uint32
- func (b *Buffer) Release(slot *Slot)
- func (b *Buffer) ReleaseBulk(slots []*Slot)
- type Slot
Constants ¶
const DefaultInitialCap = 1024
DefaultInitialCap is the default initial capacity (number of pages) per segment.
const DefaultMaxSegments = math.MaxInt32
DefaultMaxSegments is the maximum number of segments (limits total capacity).
Variables ¶
var ErrBufferFull = &spillError{"buffer full (max segments reached)"}
Error types
Functions ¶
This section is empty.
Types ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap tracks slot allocation using a bitset. Uses uint64 words for efficient 64-bit operations.
func (*Bitmap) Allocate ¶
Allocate finds and marks a free slot. Returns the slot index or (MaxUint32, false) if no free slot is available.
func (*Bitmap) IsAllocated ¶
IsAllocated returns true if the slot is marked as allocated.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a memory-mapped file used to spill dirty pages. This reduces heap pressure by storing dirty pages in mmap'd memory rather than Go-allocated heap memory. Uses multiple segments to allow growth without invalidating existing slices.
func New ¶
New creates or reopens a spill buffer at the given path. The pageSize determines the size of each slot. initialCap is the initial capacity in number of pages per segment.
func (*Buffer) Allocate ¶
Allocate allocates a slot and returns the page data slice and slot info. Automatically extends by adding new segments if needed.
func (*Buffer) AllocatedCount ¶
AllocatedCount returns the number of allocated slots.
func (*Buffer) Clear ¶
func (b *Buffer) Clear()
Clear releases all slots without closing the buffer.
func (*Buffer) Close ¶
Close closes the spill buffer. If deleteFile is true, the underlying files are also deleted.
func (*Buffer) ReleaseBulk ¶
ReleaseBulk returns multiple slots to the pool.