buffer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 9 Imported by: 92

README

IoBuffer复用

// GetIoBuffer returns IoBuffer from pool
func GetIoBuffer(size int) types.IoBuffer {
	return ibPool.take(size)
}

// PutIoBuffer returns IoBuffer to pool
func PutIoBuffer(buf types.IoBuffer) {
	if buf.Count(-1) != 0 {
		return
	}
	ibPool.give(buf)
}

Byte复用

// GetBytes returns *[]byte from byteBufferPool
func GetBytes(size int) *[]byte {
	p := getByteBufferPool()
	return p.take(size)
}

// PutBytes Put *[]byte to byteBufferPool
func PutBytes(buf *[]byte) {
	p := getByteBufferPool()
	p.give(buf)
}

Documentation

Index

Constants

View Source
const (
	AutoExpand      = -1
	MinRead         = 1 << 9
	MaxRead         = 1 << 17
	ResetOffMark    = -1
	DefaultSize     = 1 << 4
	MaxBufferLength = 1 << 20
	MaxThreshold    = 1 << 22
)

Variables

View Source
var (
	EOF                  = errors.New("EOF")
	ErrTooLarge          = errors.New("io buffer: too large")
	ErrNegativeCount     = errors.New("io buffer: negative count")
	ErrInvalidWriteCount = errors.New("io buffer: invalid write count")
	ConnReadTimeout      = 15 * time.Second
)

Functions

func GetBytes

func GetBytes(size int) *[]byte

GetBytes returns *[]byte from byteBufferPool

func PutBytes

func PutBytes(buf *[]byte)

PutBytes Put *[]byte to byteBufferPool

func PutIoBuffer

func PutIoBuffer(buf IoBuffer) error

PutIoBuffer is a a wrapper for ibPool

func SetLogFunc

func SetLogFunc(f func(msg string))

SetLogFunc use f overwrite logFunc.

Types

type ByteBufferPoolContainer

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

func NewByteBufferPoolContainer

func NewByteBufferPoolContainer() *ByteBufferPoolContainer

func (*ByteBufferPoolContainer) Reset

func (c *ByteBufferPoolContainer) Reset()

func (*ByteBufferPoolContainer) Take

func (c *ByteBufferPoolContainer) Take(size int) *[]byte

type IoBuffer

type IoBuffer = api.IoBuffer

keep this alias for compatbile. if you write new code, use api.IoBuffer instead.

func GetIoBuffer

func GetIoBuffer(size int) IoBuffer

GetIoBuffer is a wrapper for ibPool

func NewIoBuffer

func NewIoBuffer(size int) IoBuffer

NewIoBuffer is an alias for GetIoBuffer

func NewIoBufferBytes

func NewIoBufferBytes(bytes []byte) IoBuffer

func NewIoBufferEOF

func NewIoBufferEOF() IoBuffer

func NewIoBufferString

func NewIoBufferString(s string) IoBuffer

func NewPipeBuffer

func NewPipeBuffer(capacity int) IoBuffer

type IoBufferPool

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

IoBufferPool is Iobuffer Pool

func (*IoBufferPool) GetIoBuffer

func (p *IoBufferPool) GetIoBuffer(size int) IoBuffer

GetIoBuffer returns IoBuffer from pool

func (*IoBufferPool) PutIoBuffer

func (p *IoBufferPool) PutIoBuffer(buf IoBuffer) error

PutIoBuffer returns IoBuffer to pool

Jump to

Keyboard shortcuts

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