byte_alloc

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: LGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

from https://github.com/xtaci/smux/blob/master/alloc.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(size int) []byte

func Put

func Put(buf []byte)

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 1048576 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 a []byte from pool with most appropriate cap

func (*Allocator) Put

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

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