bytesPool

package module
v0.0.0-...-1af74a0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 2 Imported by: 1

README

go-bytes-pool

Simple []byte buffer pool for go backend by sync.Pool.

Go Reference

package main

import "github.com/IrineSistiana/go-bytes-pool"

func main() {
	// a pool for []bytes whose length are smaller than 65535 ((1<<16) -1))
	p := NewPool(16) 
	b := p.Get(1024)
	p.Release(b)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

func NewPool

func NewPool(bitLen int) *Pool

NewPool Creates a pool that will reuse []byte whose length is smaller than (1<<bitLen)-1 .

func (*Pool) Get

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

Get returns a *[]byte from pool with most appropriate cap. It returns a *[]byte with cap of (2^n)-1. If size > pool's maxSize, Get simply calls make([]byte, size).

func (*Pool) Release

func (p *Pool) Release(b *[]byte)

Release releases b to the pool. If cap(b) > pool's maxSize, Release is noop. b should come from Get(). Release will panic if cap(b) is not suitable for the pool.

Jump to

Keyboard shortcuts

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