mpool

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NumFixedPool = 5

	B  = 1
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
	PB = 1024 * TB
)
View Source
const (
	NoFixed = 1
	NoLock  = 2
)
View Source
const (
	Available = iota
	Unavailable
)

Variables

View Source
var PoolElemSize = [NumFixedPool]int32{64, 128, 256, 512, 1024}

Pool emement size

Functions

func DeleteMPool

func DeleteMPool(mp *MPool)

func GlobalCap

func GlobalCap() int64

func InitCap

func InitCap(cap int64)

func MPoolControl

func MPoolControl(tag string, cmd string) string

func MakeSlice

func MakeSlice[T any](n int, mp *MPool) ([]T, error)

func MakeSliceArgs

func MakeSliceArgs[T any](mp *MPool, args ...T) ([]T, error)

func MakeSliceWithCap

func MakeSliceWithCap[T any](n, cap int, mp *MPool) ([]T, error)

func ReportMemUsage

func ReportMemUsage(tag string) string

Report memory usage in json.

func TotalCrossPoolFreeCounter added in v1.1.0

func TotalCrossPoolFreeCounter() int64

Types

type MPool

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

The memory pool.

func MustNew added in v0.8.0

func MustNew(tag string) *MPool

func MustNewNoFixed added in v0.8.0

func MustNewNoFixed(tag string) *MPool

func MustNewZero

func MustNewZero() *MPool

func MustNewZeroNoFixed added in v0.8.0

func MustNewZeroNoFixed() *MPool

func NewMPool

func NewMPool(tag string, cap int64, flag int) (*MPool, error)

New a MPool. Tag is user supplied, used for debugging/diagnostics.

func (*MPool) Alloc

func (mp *MPool) Alloc(sz int) ([]byte, error)

func (*MPool) Cap

func (mp *MPool) Cap() int64

func (*MPool) CurrNB

func (mp *MPool) CurrNB() int64

func (*MPool) DisableDetailRecording

func (mp *MPool) DisableDetailRecording()

func (*MPool) EnableDetailRecording

func (mp *MPool) EnableDetailRecording()

func (*MPool) Free

func (mp *MPool) Free(bs []byte)

func (*MPool) GetSels

func (mp *MPool) GetSels() []int64

func (*MPool) Grow

func (mp *MPool) Grow(old []byte, sz int) ([]byte, error)

Grow is like reAlloc, but we try to be a little bit more aggressive on growing the slice.

func (*MPool) Grow2

func (mp *MPool) Grow2(old []byte, old2 []byte, sz int) ([]byte, error)

func (*MPool) PutSels

func (mp *MPool) PutSels(sels []int64)

func (*MPool) Report

func (mp *MPool) Report() string

func (*MPool) ReportJson

func (mp *MPool) ReportJson() string

func (*MPool) Stats

func (mp *MPool) Stats() *MPoolStats

type MPoolStats

type MPoolStats struct {
	NumAlloc      atomic.Int64 // number of allocations
	NumFree       atomic.Int64 // number of frees
	NumAllocBytes atomic.Int64 // number of bytes allocated
	NumFreeBytes  atomic.Int64 // number of bytes freed
	NumCurrBytes  atomic.Int64 // current number of bytes
	HighWaterMark atomic.Int64 // high water mark
}

Stats

func GlobalStats

func GlobalStats() *MPoolStats

func (*MPoolStats) RecordAlloc

func (s *MPoolStats) RecordAlloc(tag string, sz int64) int64

Update alloc stats, return curr bytes

func (*MPoolStats) RecordFree

func (s *MPoolStats) RecordFree(tag string, sz int64) int64

Update free stats, return curr bytes.

func (*MPoolStats) RecordManyFrees

func (s *MPoolStats) RecordManyFrees(tag string, nfree, sz int64) int64

func (*MPoolStats) Report

func (s *MPoolStats) Report(tab string) string

func (*MPoolStats) ReportJson

func (s *MPoolStats) ReportJson() string

Jump to

Keyboard shortcuts

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