mpool

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
	PB = 1024 * TB
)
View Source
const (
	NoFixed = 1 << iota
	NoLock
)
View Source
const PtrLenSize = int(unsafe.Sizeof(PtrLen{}))

Variables

View Source
var CapLimit = math.MaxInt32 // 2GB - 1

Functions

func AppendFixed

func AppendFixed[T any](mp *MPool, p *PtrLen, v T) error

func AppendFixedList

func AppendFixedList[T comparable](mp *MPool, p *PtrLen, vs []T, distinct bool) error

func DeleteMPool

func DeleteMPool(mp *MPool)

func DisableDebugPoisonOnFree

func DisableDebugPoisonOnFree()

func DisableProfiling

func DisableProfiling()

DisableProfiling turns off per-allocation stack tracking.

func EnableDebugPoisonOnFree

func EnableDebugPoisonOnFree()

func EnableProfiling

func EnableProfiling()

EnableProfiling turns on per-allocation stack tracking for off-heap mpool allocations. Tracked allocations appear in the malloc profiler output.

func FreeSlice

func FreeSlice[T any](mp *MPool, bs []T)

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, offHeap bool) ([]T, error)

func MakeSliceArgs

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

func ProfileTrackedCount

func ProfileTrackedCount() int

ProfileTrackedCount returns the total number of tracked pointers across all shards.

func ProfilingEnabled

func ProfilingEnabled() bool

ProfilingEnabled reports whether mpool profiling is active.

func PtrLenFindFixed

func PtrLenFindFixed[T comparable](p *PtrLen, v T) int

func PtrLenFromSlice

func PtrLenFromSlice[T any](p *PtrLen, slice []T)

func PtrLenToSlice

func PtrLenToSlice[T any](p *PtrLen) []T

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 MustNew added in v0.8.0

func MustNew(tag string) *MPool

func MustNewNoFixed added in v0.8.0

func MustNewNoFixed() *MPool

func MustNewNoLock

func MustNewNoLock(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, offHeap bool) ([]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) Grow

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

func (*MPool) Grow2

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

func (*MPool) ReallocZero

func (mp *MPool) ReallocZero(old []byte, sz int, offHeap bool) ([]byte, error)

ReallocZero is like Realloc, but it clears the memory.

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
	NumCrossPoolFree atomic.Int64 // number of cross pool free
	HighWaterMark    atomic.Int64 // high water mark
	// contains filtered or unexported fields
}

Mo's extremely simple memory pool. Stats

func GlobalStats

func GlobalStats() *MPoolStats

func (*MPoolStats) Init

func (s *MPoolStats) Init()

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

func (s *MPoolStats) RecordXPoolFree(detail string, nb int64)

func (*MPoolStats) Report

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

func (*MPoolStats) ReportJson

func (s *MPoolStats) ReportJson() string

type PtrLen

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

PtrLen is a known size slice.

func (*PtrLen) AppendBytes

func (p *PtrLen) AppendBytes(mp *MPool, bs []byte) error

func (*PtrLen) AppendBytesList

func (p *PtrLen) AppendBytesList(mp *MPool, other *PtrLen, distinct bool) error

func (*PtrLen) AppendRawBytes

func (p *PtrLen) AppendRawBytes(mp *MPool, bs []byte) error

func (*PtrLen) FindBytes

func (p *PtrLen) FindBytes(bs []byte) int

func (*PtrLen) Free

func (p *PtrLen) Free(mp *MPool)

func (*PtrLen) FromByteSlice

func (p *PtrLen) FromByteSlice(bs []byte)

func (*PtrLen) Len

func (p *PtrLen) Len() int

func (*PtrLen) NumberOfVarlenElements

func (p *PtrLen) NumberOfVarlenElements() int

func (*PtrLen) Ptr

func (p *PtrLen) Ptr() unsafe.Pointer

func (*PtrLen) Replace

func (p *PtrLen) Replace(mp *MPool, bs []byte) error

func (*PtrLen) ToByteSlice

func (p *PtrLen) ToByteSlice() []byte

Jump to

Keyboard shortcuts

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