Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var StdAllocator = &stdAllocator{}
StdAllocator implements Allocator but do not pre-allocate memory.
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator interface { // Alloc allocates memory with 0 len and capacity cap. Alloc(capacity int) []byte // AllocWithLen allocates memory with length and capacity. AllocWithLen(length int, capacity int) []byte // Reset resets arena offset. // Make sure all the allocated memory are not used any more. Reset() }
Allocator pre-allocates memory to reduce memory allocation cost. It is not thread-safe.
type SimpleAllocator ¶
type SimpleAllocator struct {
// contains filtered or unexported fields
}
SimpleAllocator is a simple implementation of ArenaAllocator.
func NewAllocator ¶
func NewAllocator(capacity int) *SimpleAllocator
NewAllocator creates an Allocator with a specified capacity.
func (*SimpleAllocator) Alloc ¶
func (s *SimpleAllocator) Alloc(capacity int) []byte
Alloc implements Allocator.AllocBytes interface.
func (*SimpleAllocator) AllocWithLen ¶
func (s *SimpleAllocator) AllocWithLen(length int, capacity int) []byte
AllocWithLen implements Allocator.AllocWithLen interface.
func (*SimpleAllocator) Reset ¶
func (s *SimpleAllocator) Reset()
Reset implements Allocator.Reset interface.
Click to show internal directories.
Click to hide internal directories.