mirror of
https://github.com/gwuhaolin/livego.git
synced 2021-06-01 09:10:22 +03:00
25 lines
370 B
Go
Executable File
25 lines
370 B
Go
Executable File
package pool
|
|
|
|
type Pool struct {
|
|
pos int
|
|
buf []byte
|
|
}
|
|
|
|
const maxpoolsize = 500 * 1024
|
|
|
|
func (pool *Pool) Get(size int) []byte {
|
|
if maxpoolsize-pool.pos < size {
|
|
pool.pos = 0
|
|
pool.buf = make([]byte, maxpoolsize)
|
|
}
|
|
b := pool.buf[pool.pos : pool.pos+size]
|
|
pool.pos += size
|
|
return b
|
|
}
|
|
|
|
func NewPool() *Pool {
|
|
return &Pool{
|
|
buf: make([]byte, maxpoolsize),
|
|
}
|
|
}
|