pool

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Overview

Package pool provides a pool of []byte.

Index

Constants

View Source
const (
	// MaxSegmentSize is the largest possible UDP datagram size.
	MaxSegmentSize = (1 << 16) - 1

	// RelayBufferSize is a buffer of 20 KiB to reduce the memory
	// of each TCP relay as io.Copy default buffer size is 32 KiB,
	// but the maximum packet size of vmess/shadowsocks is about
	// 16 KiB, so define .
	RelayBufferSize = 20 << 10
)

Variables

This section is empty.

Functions

func Get

func Get(size int) []byte

Get gets a []byte from default allocator with most appropriate cap.

func GetBuffer

func GetBuffer() *bytes.Buffer

func Put

func Put(buf []byte) error

Put returns a []byte to default allocator for future use.

func PutBuffer

func PutBuffer(buf *bytes.Buffer)

Types

type Allocator

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

Allocator for incoming frames, optimized to prevent overwriting after zeroing.

func NewAllocator

func NewAllocator() *Allocator

NewAllocator initiates a []byte allocator for frames less than 65536 bytes, 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 gets a []byte from pool with most appropriate cap.

func (*Allocator) Put

func (alloc *Allocator) Put(buf []byte) error

Put returns a []byte to pool for future use, which the cap must be exactly 2^n.

Jump to

Keyboard shortcuts

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