gxbytes

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: Apache-2.0 Imports: 2 Imported by: 19

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireBytes added in v1.5.0

func AcquireBytes(size int) *[]byte

AcquireBytes called by defaultBytesPool

func GetBytes

func GetBytes(size int) *[]byte

GetBytes returns *[]byte from SlicePool Deprecated instead by AcquireBytes

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 Deprecated instead by ReleaseBytes

func PutBytesBuffer

func PutBytesBuffer(buf *bytes.Buffer)

PutIoBuffer returns IoBuffer to pool

func ReleaseBytes added in v1.5.0

func ReleaseBytes(bufp *[]byte)

ReleaseBytes called by defaultBytesPool

func SetDefaultBytesPool added in v1.5.0

func SetDefaultBytesPool(bp *BytesPool)

SetDefaultBytesPool change default pool options

Types

type BytesPool added in v1.5.0

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

BytesPool hold specific size []byte

func NewBytesPool added in v1.5.0

func NewBytesPool(slotSize []int) *BytesPool

NewBytesPool creates a memory pool.

func (*BytesPool) AcquireBytes added in v1.5.0

func (bp *BytesPool) AcquireBytes(size int) *[]byte

AcquireBytes get specific make([]byte, 0, size)

func (*BytesPool) ReleaseBytes added in v1.5.0

func (bp *BytesPool) ReleaseBytes(bufp *[]byte)

ReleaseBytes ...

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 {
	BytesPool
}

SlicePool is []byte pools Deprecated

func NewSlicePool

func NewSlicePool() *SlicePool

newSlicePool returns SlicePool Deprecated instead by NewBytesPool

func (*SlicePool) Get

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

Get returns *[]byte from SlicePool

func (*SlicePool) Put

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

Put returns *[]byte to SlicePool

Jump to

Keyboard shortcuts

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