fastbuffer

package module
v0.0.0-...-4963938 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 1 Imported by: 0

README

fastbuffer-go

fastbuffer-go is type alias to [][]byte but holds the sync.Mutex and do not free []byte to os which can reduce memory allocation.

go test -v -benchmem -run="^$" github.com/detailyang/fastbuffer-go -bench "^Benchmark"
goos: darwin
goarch: amd64
pkg: github.com/detailyang/fastbuffer-go
BenchmarkBatchFastBuffer-8   	 3265705	       357 ns/op	  41.96 MB/s	       0 B/op	       0 allocs/op
PASS
ok  	github.com/detailyang/fastbuffer-go	1.556s

Documentation

Overview

Package fastbuffer implements the allocation and release for [][]byte to reduce memory allocation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastBuffer

type FastBuffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FastBuffer holds the [][]byte with sync.Mutex to reduce memory allocation.

func NewFastBuffer

func NewFastBuffer() *FastBuffer

NewFastBuffer returns a new FastBuffer.

func (*FastBuffer) Allocate

func (fb *FastBuffer) Allocate(size int) []byte

Allocate allocates the size of []byte from FastBuffer.

func (*FastBuffer) BatchRelease

func (fb *FastBuffer) BatchRelease(d [][]byte)

BatchRelease releases the [][]byte to FastBuffer.

func (*FastBuffer) Release

func (fb *FastBuffer) Release(d []byte)

Release releases the []byte to FastBuffer.

func (*FastBuffer) Reset

func (fb *FastBuffer) Reset()

Reset resets the underlying buffer.

Jump to

Keyboard shortcuts

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