alloc

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuf

func GetBuf(size int) []byte

GetBuf returns a buf from a global allocator. The reuse limit is 1 Megabytes.

func ReleaseBuf

func ReleaseBuf(b []byte)

ReleaseBuf releases the b

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

func NewAllocator

func NewAllocator(maxPoolBitsLen int) *Allocator

NewAllocator initiates a []byte allocatorL. []byte that has less than 1 << maxPoolBitsLen bytes is managed by sync.Pool. The waste(memory fragmentation) of space allocation is guaranteed to be no more than 50%.

func (*Allocator) Get

func (alloc *Allocator) Get(size int) []byte

Get returns a []byte from pool with most appropriate cap

func (*Allocator) Release

func (alloc *Allocator) Release(buf []byte)

Release releases the buf to the allocatorL.

Jump to

Keyboard shortcuts

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