pool

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: GPL-3.0 Imports: 5 Imported by: 47

Documentation

Index

Constants

View Source
const (
	// io.Copy default buffer size is 32 KiB
	// but the maximum packet size of vmess/shadowsocks is about 16 KiB
	// so define a buffer of 20 KiB to reduce the memory of each TCP relay
	RelayBufferSize = 20 * 1024

	// RelayBufferSize uses 20KiB, but due to the allocator it will actually
	// request 32Kib. Most UDPs are smaller than the MTU, and the TUN's MTU
	// set to 9000, so the UDP Buffer size set to 16Kib
	UDPBufferSize = 16 * 1024
)

Variables

This section is empty.

Functions

func Get added in v0.20.0

func Get(size int) []byte

func GetBuffer added in v1.8.0

func GetBuffer() *bytes.Buffer

func GetBytesBuffer added in v1.16.0

func GetBytesBuffer() *protobytes.BytesWriter

func Put added in v0.20.0

func Put(buf []byte) error

func PutBuffer added in v1.8.0

func PutBuffer(buf *bytes.Buffer)

func PutBytesBuffer added in v1.16.0

func PutBytesBuffer(buf *protobytes.BytesWriter)

Types

type Allocator added in v0.20.0

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

Allocator for incoming frames, optimized to prevent overwriting after zeroing

func NewAllocator added in v0.20.0

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 added in v0.20.0

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

Get a []byte from pool with most appropriate cap

func (*Allocator) Put added in v0.20.0

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