Documentation ¶
Index ¶
- func InitDefaultPools(minSize, maxSize int)
- func Make(size int) []byte
- func Make64(size uint64) []byte
- func MakeMax() []byte
- func MakeMin() []byte
- func New(size int) []byte
- func New64(size uint64) []byte
- func NewMax() []byte
- func NewMin() []byte
- func Release(buf []byte) bool
- type CapacityPools
- func (p *CapacityPools) Make(capacity int) []byte
- func (p *CapacityPools) Make64(capacity uint64) []byte
- func (p *CapacityPools) MakeMax() []byte
- func (p *CapacityPools) MakeMin() []byte
- func (p *CapacityPools) New(size int) (buf []byte)
- func (p *CapacityPools) New64(size uint64) []byte
- func (p *CapacityPools) NewMax() []byte
- func (p *CapacityPools) NewMin() []byte
- func (p *CapacityPools) Release(buf []byte) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefaultPools ¶
func InitDefaultPools(minSize, maxSize int)
InitDefaultPools initialize to the default pool.
func New ¶
Example ¶
package main import ( "fmt" "github.com/fufuok/bytespool" ) func main() { // len: 0, cap: 8192 (Default maximum) bs := bytespool.MakeMax() bs = append(bs, "abc"...) fmt.Printf("len: %d, cap: %d, %s\n", len(bs), cap(bs), bs) // Put it back into the pool after use bytespool.Release(bs) // len: 0, cap: 4 (Specified capacity, automatically adapt to the capacity scale) bs3 := bytespool.Make(3) bs3 = append(bs3, "123"...) fmt.Printf("len: %d, cap: %d, %s\n", len(bs3), cap(bs3), bs3) bytespool.Release(bs3) // len: 4, cap: 4 (Fixed length) bs4 := bytespool.New(4) // Reuse of bs3 fmt.Printf("same array: %v\n", &bs3[0] == &bs4[0]) // Contain old data fmt.Printf("bs3: %s, bs4: %s\n", bs3, bs4[:3]) copy(bs4, "xy") fmt.Printf("len: %d, cap: %d, %s\n", len(bs4), cap(bs4), bs4[:3]) bytespool.Release(bs4) }
Output: len: 3, cap: 8192, abc len: 3, cap: 4, 123 same array: true bs3: 123, bs4: 123 len: 4, cap: 4, xy3
Types ¶
type CapacityPools ¶
type CapacityPools struct {
// contains filtered or unexported fields
}
func NewCapacityPools ¶
func NewCapacityPools(minSize, maxSize int) *CapacityPools
NewCapacityPools divide into multiple pools according to the capacity scale.
func (*CapacityPools) Make ¶
func (p *CapacityPools) Make(capacity int) []byte
Make return an empty bytes pointer variable. Length is 0, default capacity is maxSize.
func (*CapacityPools) Make64 ¶ added in v0.0.2
func (p *CapacityPools) Make64(capacity uint64) []byte
func (*CapacityPools) MakeMax ¶ added in v0.0.2
func (p *CapacityPools) MakeMax() []byte
func (*CapacityPools) MakeMin ¶ added in v0.0.2
func (p *CapacityPools) MakeMin() []byte
func (*CapacityPools) New ¶
func (p *CapacityPools) New(size int) (buf []byte)
New return bytes of the specified size. Length is size, may contain old data.
func (*CapacityPools) New64 ¶ added in v0.0.2
func (p *CapacityPools) New64(size uint64) []byte
func (*CapacityPools) NewMax ¶ added in v0.0.2
func (p *CapacityPools) NewMax() []byte
func (*CapacityPools) NewMin ¶ added in v0.0.2
func (p *CapacityPools) NewMin() []byte
func (*CapacityPools) Release ¶
func (p *CapacityPools) Release(buf []byte) bool
Release put it back into the pool of the corresponding scale. Discard buffer larger than the maximum capacity.
Click to show internal directories.
Click to hide internal directories.