Documentation ¶
Index ¶
- func AcquireBytes(size int) *[]byte
- func GetBytes(size int) *[]byte
- func GetBytesBuffer() *bytes.Buffer
- func PutBytes(buf *[]byte)
- func PutBytesBuffer(buf *bytes.Buffer)
- func ReleaseBytes(bufp *[]byte)
- func SetDefaultBytesPool(bp *BytesPool)
- type BytesPool
- type New
- type ObjectPool
- type PoolObject
- type SlicePool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireBytes ¶ added in v1.5.0
AcquireBytes called by defaultBytesPool
func GetBytes ¶
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 ¶
GetBytesBuffer returns bytes.Buffer from pool
func PutBytes ¶
func PutBytes(buf *[]byte)
PutBytes Put *[]byte to SlicePool Deprecated instead by ReleaseBytes
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
NewBytesPool creates a memory pool.
func (*BytesPool) AcquireBytes ¶ added in v1.5.0
AcquireBytes get specific make([]byte, 0, size)
func (*BytesPool) ReleaseBytes ¶ added in v1.5.0
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
Click to show internal directories.
Click to hide internal directories.