gxbytes

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2019 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBytes

func GetBytes(size int) *[]byte

GetBytes returns *[]byte from SlicePool

Example
str := "hello, world"
// Obtain a buffer from the pool.
bufPtr := GetBytes(len(str))
defer PutBytes(bufPtr)
buf := *bufPtr
copy(buf, []byte(str))
if string(buf) != str {
	panic("wrong slice buffer content!!")
}
Output:

func GetBytesBuffer

func GetBytesBuffer() *bytes.Buffer

GetBytesBuffer returns bytes.Buffer from pool

func PutBytes

func PutBytes(buf *[]byte)

PutBytes Put *[]byte to SlicePool

func PutBytesBuffer

func PutBytesBuffer(buf *bytes.Buffer)

PutIoBuffer returns IoBuffer to pool

Types

type New

type New func() PoolObject

type ObjectPool

type ObjectPool struct {
	New New
	// contains filtered or unexported fields
}

Pool is bytes.Buffer Pool

func NewObjectPool

func NewObjectPool(n New) *ObjectPool

func (*ObjectPool) Get

func (p *ObjectPool) Get() PoolObject

take returns *bytes.Buffer from Pool

func (*ObjectPool) Put

func (p *ObjectPool) Put(o PoolObject)

give returns *byes.Buffer to Pool

type PoolObject

type PoolObject interface {
	Reset()
}

Pool object

type SlicePool

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

SlicePool is []byte pools

func NewSlicePool

func NewSlicePool() *SlicePool

newSlicePool returns SlicePool

func (*SlicePool) Get

func (p *SlicePool) Get(size int) *[]byte

Get returns *[]byte from SlicePool

func (*SlicePool) Put

func (p *SlicePool) Put(buf *[]byte)

Put returns *[]byte to SlicePool

Jump to

Keyboard shortcuts

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