xbytes

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

Xbytes

Install

go get -u github.com/chenquan/go-pkg/xbytes

Use

package main

import (
	"github.com/chenquan/go-pkg/xbytes"
)

func main() {
	pool := xbytes.GetNBytesPool(10)
	// Get
	b := pool.Get()
	_ = b
	// Recover 
	pool.Put(b)
}

Benchmark

goos: windows
goarch: amd64
pkg: github.com/chenquan/go-pxg/xbytes
cpu: Intel(R) Core(TM) i5-8265UC CPU @ 1.60GHz
BenchmarkMakeBytes-8                2281            591449 ns/op         2264156 B/op         28 allocs/op
BenchmarkGetNBytesPool-8           10000            127145 ns/op            4811 B/op        149 allocs/op

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
}

Pool Represents a pool of the same byte size.

func GetNBytesPool

func GetNBytesPool(nBytes int) *Pool

GetNBytesPool returns a bytes sync.Pool. It is recommended to use n Byte greater than or equal to 64.

func (*Pool) Get

func (p *Pool) Get() (bytes []byte)

Get Returns a bytes of slice.

func (*Pool) Put

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

Put Recovers a byte slice.

Jump to

Keyboard shortcuts

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