buffer

package
v0.0.0-...-3279554 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package buffer implements a pool of pointers to byte slices.

Example usage pattern

p := buffer.Get(size)
b := *p	// Now you can use b in any way you need.
...
// When b will not be used anymore
buffer.Put(p)
...
// If b or p are not going out of scope soon, optionally
b = nil
p = nil

Otherwise the pool cannot release the buffer on garbage collection.

Do not do

p := buffer.Get(size)
b := *p
...
buffer.Put(&b)

or

b := *buffer.Get(size)
...
buffer.Put(&b)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CGet

func CGet(size int) *[]byte

CGet returns a pointer to a byte slice of len size. The pointed to byte slice is zeroed up to its cap. CGet panics for size < 0.

CGet is safe for concurrent use by multiple goroutines.

func Get

func Get(size int) *[]byte

Get returns a pointer to a byte slice of len size. The pointed to byte slice is not zeroed. Get panics for size < 0.

Get is safe for concurrent use by multiple goroutines.

func Put

func Put(p *[]byte)

Put puts a pointer to a byte slice into a pool for possible later reuse by CGet or Get.

Put is safe for concurrent use by multiple goroutines.

Types

type Bytes

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

Bytes is similar to bytes.Buffer but may generate less garbage when properly Closed. Zero value is ready to use.

func (*Bytes) Bytes

func (b *Bytes) Bytes() []byte

Bytes return the content of b. The result is R/O.

func (*Bytes) Close

func (b *Bytes) Close() error

Close will recycle the underlying storage, if any. After Close, b is again the zero value.

func (*Bytes) Len

func (b *Bytes) Len() int

Len returns the size of content in b.

func (*Bytes) Reset

func (b *Bytes) Reset()

Reset discard the content of Bytes while keeping the internal storage, if any.

func (*Bytes) Write

func (b *Bytes) Write(p []byte) (int, error)

Write writes p into b and returns (len(p), nil).

func (*Bytes) WriteByte

func (b *Bytes) WriteByte(p byte) error

WriteByte writes p into b and returns nil.

func (*Bytes) WriteString

func (b *Bytes) WriteString(s string) (int, error)

WriteString writes s to b and returns (len(s), nil).

func (*Bytes) WriteTo

func (b *Bytes) WriteTo(w io.Writer) (int64, error)

WriteTo writes b's content to w and returns the number of bytes written to w and an error, if any.

Jump to

Keyboard shortcuts

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