1
0
mirror of https://github.com/siddontang/go.git synced 2025-05-01 22:18:22 +08:00
2014-07-08 14:48:55 +08:00

29 lines
383 B
Go

package arena
type Arena struct {
buf []byte
size int
}
func NewArena(size int) *Arena {
a := new(Arena)
a.size = size
a.buf = make([]byte, size, size)
return a
}
func (a *Arena) Make(size int) []byte {
if a.size < size {
return make([]byte, size)
} else if len(a.buf) < size {
a.buf = make([]byte, a.size)
}
b := a.buf[0:size]
a.buf = a.buf[size:]
return b
}