offheap

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 6 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

Overview

Package offheap holds large buffers (rasters, clipboard payloads) in memory-go memory instead of on the Go heap, so their pages go back to the system the moment their owner frees them rather than lingering as garbage that raises the heap goal.

Index

Constants

This section is empty.

Variables

View Source
var ErrBufferDone = errors.New("offheap: buffer already taken or freed")

ErrBufferDone reports a write to, or a Take of, a Buffer already taken or freed.

View Source
var ErrBufferFull = errors.New("offheap: buffer full")

ErrBufferFull reports a write past the most a Buffer holds.

Functions

func Clone

func Clone(mem *memory.Shared, src []byte) (memory.Slice[byte], error)

Clone copies src into memory mem holds, and returns the slice to free it by. src is not empty.

func Free

func Free(mem *memory.Shared, bufs ...memory.Slice[byte]) error

Free frees buffers mem holds and hands the pages back to the system at once: the allocator otherwise keeps the newest region of each size committed for reuse, a whole buffer's worth of resident memory. Nothing may read the buffers any more.

func NewRGBA

func NewRGBA(mem *memory.Shared, w, h int) (*image.RGBA, memory.Slice[byte], error)

NewRGBA is a zeroed w x h image whose pixels mem holds, and the slice to free them by. Both sides are positive.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is an io.Writer whose bytes mem holds, for a payload of unknown size: it grows by doubling, from bufferChunk, never past its most. It holds the only handle to its memory, so no stale handle outlives a resize. One goroutine may write while another takes or frees it: a write after that fails with ErrBufferDone instead of touching freed memory.

func NewBuffer

func NewBuffer(mem *memory.Shared, limit int) (*Buffer, error)

NewBuffer is an empty Buffer holding at most limit bytes, which is positive.

func (*Buffer) Free

func (b *Buffer) Free() error

Free frees whatever the Buffer holds and refuses writes afterwards. Freeing it again, or after Take, does nothing.

func (*Buffer) Take

func (b *Buffer) Take() (memory.Slice[byte], error)

Take hands over the bytes written, trimmed to their length, as the caller's slice to free; empty when nothing was written. The Buffer holds nothing afterwards and refuses writes.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

Write appends p whole, or nothing: ErrBufferFull past the most, ErrBufferDone once taken or freed.

Jump to

Keyboard shortcuts

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