mem

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrowLen added in v0.4.0

func GrowLen[S ~[]E, E any](s S, n int) S

GrowLen increases the slice's length by n elements.

Types

type AllocationCache

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

AllocationCache is a trivial cache of allocations. Put appends a value to a slice and Get pops a value from the slice, or allocates a new value.

func (*AllocationCache[T]) Get

func (c *AllocationCache[T]) Get() *T

func (*AllocationCache[T]) Put

func (c *AllocationCache[T]) Put(x *T)

type BucketSlice

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

BucketSlice is like a slice, but grows one bucket at a time, instead of growing exponentially. This allows for overall lower memory usage when the total capacity isn't known ahead of time, at the cost of more overall allocations.

func (*BucketSlice[T]) Append

func (l *BucketSlice[T]) Append(v T) *T

Append appends v to the slice and returns a pointer to the new element.

func (*BucketSlice[T]) Get

func (l *BucketSlice[T]) Get(i int) T

func (*BucketSlice[T]) Grow added in v0.4.0

func (l *BucketSlice[T]) Grow() *T

Grow grows the slice by one and returns a pointer to the new element, without overwriting it.

func (*BucketSlice[T]) GrowN added in v0.4.0

func (l *BucketSlice[T]) GrowN(n int)

GrowN grows the slice by n elements.

func (*BucketSlice[T]) Len

func (l *BucketSlice[T]) Len() int

func (*BucketSlice[T]) Ptr

func (l *BucketSlice[T]) Ptr(i int) *T

func (*BucketSlice[T]) Reset

func (l *BucketSlice[T]) Reset()

func (*BucketSlice[T]) Set

func (l *BucketSlice[T]) Set(i int, v T)

func (*BucketSlice[T]) Truncate

func (l *BucketSlice[T]) Truncate(n int)

type ConcurrentSliceCache

type ConcurrentSliceCache[E any, T ~[]E] struct {
	// contains filtered or unexported fields
}

ConcurrentSliceCache caches slices, grouped by capacities. When requesting a slice, the requested capacity is rounded up to the next group and then fetched from a sync.Pool dedicated to that group.

func NewConcurrentSliceCache

func NewConcurrentSliceCache[E any, T ~[]E]() *ConcurrentSliceCache[E, T]

func (*ConcurrentSliceCache[E, T]) Get

func (c *ConcurrentSliceCache[E, T]) Get(minCap int) T

func (*ConcurrentSliceCache[E, T]) Put

func (c *ConcurrentSliceCache[E, T]) Put(s T)

type ReusableOps

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

func (*ReusableOps) Get

func (rops *ReusableOps) Get() *op.Ops

get resets and returns an op.Ops

Jump to

Keyboard shortcuts

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