Documentation
¶
Overview ¶
Package throughputbuffer provides a high throughput indefinitely growing io.ReadWriter. It does the minimum amount of copies (1 per read + 1 per write) and never has to move bytes in the buffer.
Memory is freed once read.
Index ¶
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Clone() *Buffer
- func (b *Buffer) Len() int
- func (b *Buffer) Read(p []byte) (int, error)
- func (b *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (b *Buffer) Reset()
- func (b *Buffer) Write(p []byte) (int, error)
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- type BufferPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a io.ReadWriter that can grow infinitely and does the minimum amount of copies (1 per read + 1 per write) and never has to move bytes.
func (*Buffer) Read ¶
Read consumes len(p) bytes from the buffer (or less if the buffer is smaller). The only error it can return is io.EOF.
func (*Buffer) ReadFrom ¶
ReadFrom reads all data from r and return the number of bytes read and the error from the reader.
func (*Buffer) Reset ¶ added in v0.2.0
func (b *Buffer) Reset()
Reset discards the contents back to the pool. The Buffer can be reused after this.
func (*Buffer) Write ¶
Write the data into the buffer and return len(p), nil. It always returns a nil error.
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool holds a sync.Pool of byte slices and can be used to create new Buffers.
func New ¶
func New(blocksize int) *BufferPool
New creates a new BufferPool. The blockSize is the size of the []byte slices internally. The blocksize should be within a few orders of magnitude of the expected size of your buffers. Using a larger blocksize results in more memory being held but unused, a smaller blocksize takes a bit more CPU cycles.
func (*BufferPool) Get ¶
func (p *BufferPool) Get() *Buffer
Get creates a new Buffer using byte slices from this pool.