malloc

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MB = 1 << 20
	GB = 1 << 30
)

Variables

This section is empty.

Functions

func NewFixedSizeMmapAllocator added in v1.2.1

func NewFixedSizeMmapAllocator(
	size uint64,
) *fixedSizeMmapAllocator

func NewFixedSizeSyncPoolAllocator added in v1.2.1

func NewFixedSizeSyncPoolAllocator(size uint64) *fixedSizeSyncPoolAllocator

func SetDefaultConfig added in v1.2.1

func SetDefaultConfig(delta Config)

Types

type AllocateInfo added in v1.2.1

type AllocateInfo struct {
	Deallocator Deallocator
	Size        uint64
}

type Allocator added in v1.2.1

type Allocator interface {
	Allocate(size uint64, hint Hints) (unsafe.Pointer, Deallocator, error)
}

func GetDefault added in v1.2.1

func GetDefault(defaultConfig *Config) Allocator

type AtomicInteger added in v1.2.1

type AtomicInteger[T any] interface {
	Add(T) T
	Load() T
}

type CAllocator added in v1.2.1

type CAllocator struct {
}

func NewCAllocator added in v1.2.1

func NewCAllocator() *CAllocator

func (*CAllocator) Allocate added in v1.2.1

func (c *CAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

func (*CAllocator) Deallocate added in v1.2.1

func (c *CAllocator) Deallocate(ptr unsafe.Pointer, hints Hints)

type CheckedAllocator added in v1.2.1

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

func NewCheckedAllocator added in v1.2.1

func NewCheckedAllocator(upstream Allocator, fraction uint32) *CheckedAllocator

func (*CheckedAllocator) Allocate added in v1.2.1

func (c *CheckedAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

type Class added in v1.2.1

type Class[T FixedSizeAllocator] struct {
	// contains filtered or unexported fields
}

type ClassAllocator added in v1.2.1

type ClassAllocator[T FixedSizeAllocator] struct {
	// contains filtered or unexported fields
}

func NewClassAllocator added in v1.2.1

func NewClassAllocator[T FixedSizeAllocator](
	newAllocator func(size uint64) T,
) *ClassAllocator[T]

func (*ClassAllocator[T]) Allocate added in v1.2.1

func (c *ClassAllocator[T]) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

type Config added in v1.2.1

type Config struct {

	// Allocator controls which allocator to use
	Allocator *string `toml:"allocator"`

	// CheckFraction controls the fraction of checked deallocations
	// On average, 1 / fraction of deallocations will be checked for double free or missing free
	CheckFraction *uint32 `toml:"check-fraction"`

	// FullStackFraction controls the fraction of full stack collecting in profile sampling
	// On average, 1 / fraction of allocations will be sampled with full stack information
	FullStackFraction *uint32 `toml:"full-stack-fraction"`

	// EnableMetrics indicates whether to expose metrics to prometheus
	EnableMetrics *bool `toml:"enable-metrics"`
}

type CounterInteger added in v1.2.1

type CounterInteger interface {
	int32 | int64 | uint32 | uint64
}

type Deallocator added in v1.2.1

type Deallocator interface {
	Deallocate(ptr unsafe.Pointer, hint Hints)
}

func ChainDeallocator added in v1.2.1

func ChainDeallocator(dec1 Deallocator, dec2 Deallocator) Deallocator

type FixedSizeAllocator added in v1.2.1

type FixedSizeAllocator interface {
	Allocate(hint Hints) (unsafe.Pointer, Deallocator, error)
}

type FuncDeallocator added in v1.2.1

type FuncDeallocator func(ptr unsafe.Pointer)

func (FuncDeallocator) Deallocate added in v1.2.1

func (f FuncDeallocator) Deallocate(ptr unsafe.Pointer, hints Hints)

type FunctionKey added in v1.2.1

type FunctionKey struct {
	Name string
}

type HeapSampleValues added in v1.2.1

type HeapSampleValues struct {
	AllocatedObjects ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	AllocatedBytes   ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	InuseObjects     ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	InuseBytes       ShardedCounter[int64, atomic.Int64, *atomic.Int64]
}

func (*HeapSampleValues) DefaultSampleType added in v1.2.1

func (h *HeapSampleValues) DefaultSampleType() string

func (*HeapSampleValues) Init added in v1.2.1

func (h *HeapSampleValues) Init()

func (*HeapSampleValues) SampleTypes added in v1.2.1

func (h *HeapSampleValues) SampleTypes() []*profile.ValueType

func (*HeapSampleValues) Values added in v1.2.1

func (h *HeapSampleValues) Values() []int64

type Hints added in v1.2.1

type Hints uint64
const (
	NoHints    Hints = 0
	DoNotReuse Hints = 1 << iota
	NoClear
)

type LocationKey added in v1.2.1

type LocationKey struct {
	PC       uintptr
	Function string
}

type MetricsAllocator added in v1.2.1

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

func NewMetricsAllocator added in v1.2.1

func NewMetricsAllocator(upstream Allocator) *MetricsAllocator

func (*MetricsAllocator) Allocate added in v1.2.1

func (m *MetricsAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

type ProfileAllocator added in v1.2.1

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

func NewProfileAllocator added in v1.2.1

func NewProfileAllocator(
	upstream Allocator,
	profiler *Profiler[HeapSampleValues, *HeapSampleValues],
	fraction uint32,
) *ProfileAllocator

func (*ProfileAllocator) Allocate added in v1.2.1

func (p *ProfileAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

type Profiler added in v1.2.1

type Profiler[T any, P interface {
	*T
	SampleValues
}] struct {
	// contains filtered or unexported fields
}

func NewProfiler added in v1.2.1

func NewProfiler[T any, P interface {
	*T
	SampleValues
}]() *Profiler[T, P]

func (*Profiler[T, P]) Sample added in v1.2.1

func (p *Profiler[T, P]) Sample(
	skip int,
	fullStackFraction uint32,
) P

func (*Profiler[T, P]) Write added in v1.2.1

func (p *Profiler[T, P]) Write(w io.Writer) error

type SampleInfo added in v1.2.1

type SampleInfo[T any] struct {
	Values    T
	Locations []*profile.Location
}

type SampleKey added in v1.2.1

type SampleKey struct {
	Hash uint64
}

type SampleValues added in v1.2.1

type SampleValues interface {
	Init()
	SampleTypes() []*profile.ValueType
	DefaultSampleType() string
	Values() []int64
}

type ShardedAllocator added in v1.2.1

type ShardedAllocator []Allocator

func NewShardedAllocator added in v1.2.1

func NewShardedAllocator(numShards int, newShard func() Allocator) ShardedAllocator

func (ShardedAllocator) Allocate added in v1.2.1

func (s ShardedAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

type ShardedCounter added in v1.2.1

type ShardedCounter[T CounterInteger, A any, P interface {
	*A
	AtomicInteger[T]
}] struct {
	// contains filtered or unexported fields
}

func NewShardedCounter added in v1.2.1

func NewShardedCounter[T CounterInteger, A any, P interface {
	*A
	AtomicInteger[T]
}](shards int) *ShardedCounter[T, A, P]

func (*ShardedCounter[T, A, P]) Add added in v1.2.1

func (s *ShardedCounter[T, A, P]) Add(v T)

func (*ShardedCounter[T, A, P]) Load added in v1.2.1

func (s *ShardedCounter[T, A, P]) Load() (ret T)

type SizeBoundedAllocator added in v1.2.1

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

func NewSizeBoundedAllocator added in v1.2.1

func NewSizeBoundedAllocator(upstream Allocator, maxSize uint64, counter *atomic.Uint64) *SizeBoundedAllocator

func (*SizeBoundedAllocator) Allocate added in v1.2.1

func (s *SizeBoundedAllocator) Allocate(size uint64, hints Hints) (unsafe.Pointer, Deallocator, error)

Jump to

Keyboard shortcuts

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