pool

package
v4.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTimer

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

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) *Buffer

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

func (*Allocator) Release

func (alloc *Allocator) Release(buf *Buffer)

Release releases the buf to the allocatorL.

type Buffer

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

func GetBuf

func GetBuf(size int) *Buffer

GetBuf returns a *Buffer from pool with most appropriate cap. It panics if size < 0.

func PackBuffer

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

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

func (*Buffer) AllBytes

func (b *Buffer) AllBytes() []byte

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Release

func (b *Buffer) Release()

func (*Buffer) SetLen

func (b *Buffer) SetLen(l int)

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