Documentation ¶
Overview ¶
Package bytebufferpool implements a pool of byte buffers with anti-fragmentation protection.
The pool may waste limited amount of memory due to fragmentation. This amount equals to the maximum total size of the byte buffers in concurrent use.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Release ¶
func Release(b *ByteBuffer)
Release returns byte buffer to the pool.
ByteBuffer.B mustn't be touched after returning it to the pool. Otherwise data races will occur.
Types ¶
type ByteBuffer ¶
type ByteBuffer struct { // B is a byte buffer to use in append-like workloads. // See example code for details. B []byte }
ByteBuffer provides byte buffer, which can be used for minimizing memory allocations.
ByteBuffer may be used with functions appending data to the given []byte slice. See example code for details.
Use Acquire for obtaining an empty byte buffer.
Example ¶
package main import ( "fmt" "github.com/beyondblog/k8s-web-terminal/Godeps/_workspace/src/github.com/valyala/bytebufferpool" ) func main() { bb := bytebufferpool.Acquire() bb.WriteString("first line\n") bb.Write([]byte("second line\n")) bb.B = append(bb.B, "third line\n"...) fmt.Printf("bytebuffer contents=%q", bb.B) // It is safe to release byte buffer now, since it is // no longer used. bytebufferpool.Release(bb) }
Output:
func Acquire ¶
func Acquire() *ByteBuffer
Acquire returns an empty byte buffer from the pool.
Acquired byte buffer may be returned to the pool via Release call. This reduces the number of memory allocations required for byte buffer management.
func (*ByteBuffer) SetString ¶
func (b *ByteBuffer) SetString(s string)
SetString sets ByteBuffer.B to s
func (*ByteBuffer) Write ¶
func (b *ByteBuffer) Write(p []byte) (int, error)
Write implements io.Writer - it appends p to ByteBuffer.B
func (*ByteBuffer) WriteString ¶
func (b *ByteBuffer) WriteString(s string) (int, error)
WriteString appends s to ByteBuffer.B