memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package memory provides memory management utilities including pooling.

Index

Constants

This section is empty.

Variables

View Source
var BufferPool = NewPool(func() *Buffer {
	return NewBuffer(8192)
})

BufferPool is a pool for reusable buffers.

View Source
var ByteSlicePool = NewPool(func() []byte {
	return make([]byte, 0, 4096)
})

ByteSlicePool is a pool for byte slices (4KB default capacity).

View Source
var Float64SlicePool = NewPool(func() []float64 {
	return make([]float64, 0, 1024)
})

Float64SlicePool is a pool for float64 slices (1024 default capacity).

View Source
var IntSlicePool = NewPool(func() []int {
	return make([]int, 0, 1024)
})

IntSlicePool is a pool for int slices (1024 default capacity).

View Source
var MapStringAnyPool = NewPool(func() map[string]any {
	return make(map[string]any, 256)
})

MapStringAnyPool is a pool for map[string]any (256 default capacity).

View Source
var StringSlicePool = NewPool(func() []string {
	return make([]string, 0, 512)
})

StringSlicePool is a pool for string slices (512 default capacity).

Functions

func PutBuffer

func PutBuffer(buf *Buffer)

PutBuffer returns a buffer to the pool.

Types

type Buffer

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

Buffer is a reusable buffer for efficient I/O operations.

func GetBuffer

func GetBuffer() *Buffer

GetBuffer gets a buffer from the pool.

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer creates a new buffer with the specified size.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the current buffer contents.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the buffer.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the current length of data in the buffer.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer for reuse.

func (*Buffer) Write

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

Write writes data to the buffer.

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a generic memory pool for reusing objects.

func NewPool

func NewPool[T any](newFn func() T) *Pool[T]

NewPool creates a new memory pool with the given constructor function.

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

Get retrieves an object from the pool.

func (*Pool[T]) Put

func (p *Pool[T]) Put(item T)

Put returns an object to the pool for reuse.

Jump to

Keyboard shortcuts

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