mpool

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NumFixedPool = 7

	B  = 1
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
	PB = 1024 * TB
)

Variables

View Source
var Large = []int{32 * 1024, 16 * 1024, 8 * 1024, 4 * 1024, 1024, 1024, 1024}
View Source
var Mid = []int{4096, 4096, 1024, 1024, 1024, 512, 512}
View Source
var NoFixed = []int{0, 0, 0, 0, 0, 0, 0}

Fixed pool configurations. Number of entries in fixed pool.

Small: esp, 0 is a valid value.

View Source
var PoolElemSize = []int{64, 128, 256, 512, 1024, 2048, 4096}

Pool emement size

View Source
var Small = []int{1024, 1024, 1024, 1024, 512, 0, 0}
View Source
var ZeroSlice = make([]byte, 4096)

Zeros, enough for largest pool element

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.

Types

type MPool

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

The memory pool.

func MustNewZero

func MustNewZero() *MPool

For test.

func MustNewZeroWithTag

func MustNewZeroWithTag(tag string) *MPool

func NewMPool

func NewMPool(tag string, cap int64, sz []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) Decrease

func (mp *MPool) Decrease(nb int64)

func (*MPool) DisableDetailRecording

func (mp *MPool) DisableDetailRecording()

func (*MPool) EnableDetailRecording

func (mp *MPool) EnableDetailRecording()

func (*MPool) FixedPoolStats

func (mp *MPool) FixedPoolStats(i int) *MPoolStats

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) Increase

func (mp *MPool) Increase(nb int64) error

func (*MPool) PutSels

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

func (*MPool) Realloc

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

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
	NumGoAlloc    atomic.Int64 // number of go runtime alloc
	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