arena

package
v2.1.0-rc.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL