mirror of https://github.com/gwuhaolin/livego.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
369 B
24 lines
369 B
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), |
|
} |
|
}
|
|
|