allocator

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 2 Imported by: 0

Documentation

Overview

Package allocator implements byte slice pooling management to reduce the pressure of memory allocation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Free

func Free(bts interface{})

Free releases the bytes to pool.

func Malloc

func Malloc(size int) ([]byte, interface{})

Malloc gets a []byte from pool. The second return param is used to Free.

Types

type ClassAllocator

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

ClassAllocator is a bytes pool. The size of bytes satisfies 1 << n.

func NewClassAllocator

func NewClassAllocator() *ClassAllocator

NewClassAllocator creates a new ClassAllocator.

func (*ClassAllocator) Free

func (a *ClassAllocator) Free(bts interface{})

Free releases the bytes to pool.

func (*ClassAllocator) Malloc

func (a *ClassAllocator) Malloc(size int) ([]byte, interface{})

Malloc gets a []byte from pool. The second return param is used to Free. We may also use first return param to Free bytes, but this causes an additional heap allocation. See https://github.com/golang/go/issues/8618 for more details.

Jump to

Keyboard shortcuts

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