pool

package
Version: v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuf added in v1.5.2

func GetBuf(size int) []byte

GetBuf returns a buf from a global allocator. The reuse limit is 1 Megabytes.

func GetTimer

func GetTimer(t time.Duration) *time.Timer

func PackBuffer

func PackBuffer(m *dns.Msg) (wire, buf []byte, err error)

func ReleaseBuf added in v1.5.2

func ReleaseBuf(b []byte)

ReleaseBuf releases the b

func ReleaseTimer

func ReleaseTimer(timer *time.Timer)

func ResetAndDrainTimer

func ResetAndDrainTimer(timer *time.Timer, d time.Duration)

Types

type Allocator

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

func NewAllocator

func NewAllocator(maxPoolBitsLen int) *Allocator

NewAllocator initiates a []byte allocatorL. []byte that has less than 1 << maxPoolBitsLen bytes is managed by sync.Pool. The waste(memory fragmentation) of space allocation is guaranteed to be no more than 50%.

func (*Allocator) Get

func (alloc *Allocator) Get(size int) []byte

Get returns a []byte from pool with most appropriate cap

func (*Allocator) Release added in v1.5.2

func (alloc *Allocator) Release(buf []byte)

Release releases the buf to the allocatorL.

type BytesBufPool

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

func NewBytesBufPool

func NewBytesBufPool(initSize int) *BytesBufPool

func (*BytesBufPool) Get

func (p *BytesBufPool) Get() *bytes.Buffer

func (*BytesBufPool) Release

func (p *BytesBufPool) Release(b *bytes.Buffer)

Jump to

Keyboard shortcuts

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