package mem

import "google.golang.org/grpc/internal/mem"

Package mem provides utilities that facilitate memory reuse in byte slices that are used as buffers.

Index

Types

type BinaryTieredBufferPool

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

BinaryTieredBufferPool is a buffer pool that uses multiple sub-pools with power-of-two sizes.

func NewBinaryTieredBufferPool

func NewBinaryTieredBufferPool(powerOfTwoExponents ...uint8) (*BinaryTieredBufferPool, error)

NewBinaryTieredBufferPool returns a BufferPool backed by multiple sub-pools. This structure enables O(1) lookup time for Get and Put operations.

The arguments provided are the exponents for the buffer capacities (powers of 2), not the raw byte sizes. For example, to create a pool of 16KB buffers (2^14 bytes), pass 14 as the argument.

func NewDirtyBinaryTieredBufferPool

func NewDirtyBinaryTieredBufferPool(powerOfTwoExponents ...uint8) (*BinaryTieredBufferPool, error)

NewDirtyBinaryTieredBufferPool returns a BufferPool backed by multiple sub-pools. It is similar to NewBinaryTieredBufferPool but it does not initialize the buffers before returning them.

func (*BinaryTieredBufferPool) Get

func (b *BinaryTieredBufferPool) Get(size int) *[]byte

Get returns a buffer with specified length from the pool.

func (*BinaryTieredBufferPool) Put

func (b *BinaryTieredBufferPool) Put(buf *[]byte)

Put returns a buffer to the pool.

type NopBufferPool

type NopBufferPool struct{}

NopBufferPool is a buffer pool that returns new buffers without pooling.

func (NopBufferPool) Get

func (NopBufferPool) Get(length int) *[]byte

Get returns a buffer with specified length from the pool.

func (NopBufferPool) Put

func (NopBufferPool) Put(*[]byte)

Put returns a buffer to the pool.

type TieredBufferPool

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

TieredBufferPool implements the BufferPool interface with multiple tiers of buffer pools for different sizes of buffers.

func NewTieredBufferPool

func NewTieredBufferPool(poolSizes ...int) *TieredBufferPool

NewTieredBufferPool returns a BufferPool implementation that uses multiple underlying pools of the given pool sizes.

func (*TieredBufferPool) Get

func (p *TieredBufferPool) Get(size int) *[]byte

Get returns a buffer with specified length from the pool.

func (*TieredBufferPool) Put

func (p *TieredBufferPool) Put(buf *[]byte)

Put returns a buffer to the pool.

Source Files

buffer_pool.go

Version
v1.81.0-dev
Published
Mar 6, 2026
Platform
js/wasm
Imports
5 packages
Last checked
2 hours ago

Tools for package owners.