bytesPool

package module
v0.0.0-...-c72bd97 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() {
	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 to reuse []byte buffers if the length of those buffers are 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 is too big, Get simply calls make([]byte, size).

func (*Pool) Release

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

Release releases b to the pool. If cap(b) is too big, 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