Source File
pool.go
Belonging Package
github.com/gobwas/pool/pbytes
// +build !pool_sanitizepackage pbytesimport// Pool contains logic of reusing byte slices of various size.type Pool struct {pool *pool.Pool}// New creates new Pool that reuses slices which size is in logarithmic range// [min, max].//// Note that it is a shortcut for Custom() constructor with Options provided by// pool.WithLogSizeMapping() and pool.WithLogSizeRange(min, max) calls.func (, int) *Pool {return &Pool{pool.New(, )}}// New creates new Pool with given options.func ( ...pool.Option) *Pool {return &Pool{pool.Custom(...)}}// Get returns probably reused slice of bytes with at least capacity of c and// exactly len of n.func ( *Pool) (, int) []byte {if > {panic("requested length is greater than capacity")}, := .pool.Get()if != nil {:= .([]byte)= [:]return}return make([]byte, , )}// Put returns given slice to reuse pool.// It does not reuse bytes whose size is not power of two or is out of pool// min/max range.func ( *Pool) ( []byte) {.pool.Put(, cap())}// GetCap returns probably reused slice of bytes with at least capacity of n.func ( *Pool) ( int) []byte {return .Get(0, )}// GetLen returns probably reused slice of bytes with at least capacity of n// and exactly len of n.func ( *Pool) ( int) []byte {return .Get(, )}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |