internal: github.com/cznic/internal/buffer Index | Files

package buffer

import "github.com/cznic/internal/buffer"

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

Package Files

buffer.go

func CGet Uses

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 Uses

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 Uses

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.

type Bytes Uses

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 Uses

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

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

func (*Bytes) Close Uses

func (b *Bytes) Close() error

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

func (*Bytes) Len Uses

func (b *Bytes) Len() int

Len returns the size of content in b.

func (*Bytes) Reset Uses

func (b *Bytes) Reset()

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

func (*Bytes) Write Uses

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

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

func (*Bytes) WriteByte Uses

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

WriteByte writes p into b and returns nil.

func (*Bytes) WriteString Uses

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

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

func (*Bytes) WriteTo Uses

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.

Package buffer imports 2 packages (graph) and is imported by 16 packages. Updated 2017-01-24. Refresh now. Tools for package owners.