go/arena/arena.go

29 lines
383 B
Go
Raw Normal View History

2014-07-08 10:48:55 +04:00
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
}