pool

package
v1.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMsgBuf

func GetMsgBuf(size int) []byte

func GetTimer

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

func PackBuffer

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

func ReleaseMsgBuf

func ReleaseMsgBuf(buf []byte)

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 for dns.Msg less than 65536 bytes, 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 a []byte from pool with most appropriate cap

func (*Allocator) Put

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

Put returns a []byte to pool for future use, which the cap must be exactly 2^n

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