1
0
mirror of https://github.com/siddontang/go.git synced 2025-04-26 13:48:56 +08:00
2014-10-29 23:12:22 +08:00

31 lines
413 B
Go

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