pool

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuf

func GetBuf(size int) []byte

GetBuf returns a []byte from pool with most appropriate cap. It panics if size < 0.

func GetTimer

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

func PackBuffer

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

PackBuffer packs the dns msg m to wire format. Callers should release the buf by calling ReleaseBuf after they have done with the wire []byte.

func ReleaseBuf

func ReleaseBuf(b []byte)

ReleaseBuf puts the buf to the pool.

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() *Allocator

NewAllocator initiates a []byte Allocator. 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

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