Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CheckInvariants = false
Controls whether representation invariants are checked in buffer.repOk. When enabled, a panic occurs when an invariant is found to be violated.
var ErrEmptyPool = errors.New("buffer_pool.Buffer: pool is empty")
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer interface { // Returns a MemView of length Len() that holds the unread portion of the // buffer. The MemView is valid for use only until the next buffer // modification (that is, only until the next call to a method like Read, // Write, Reset, or Truncate). The MemView aliases the buffer content at least // until the next buffer modification, so changes to the MemView will affect // the result of future reads. Bytes() memview.MemView // Returns the number of bytes of the unread portion of the buffer; Len() == // Bytes().Len(). Len() int // Empties the buffer. An alias for Release. Reset() // Empties the buffer and returns its underlying storage to the pool. Release() // Write(p) appends the contents of the slice p to the buffer, obtaining // additional storage from the pool as needed. // // Returns the number of bytes written from p and EmptyPool if the write // stopped early. io.Writer // ReadFrom(r) copies the contents of the io.Reader r into the buffer until // EOF or an error is encountered. Additional storage is obtained from the // pool as needed. // // Returns the number of bytes copied. Any error except EOF encountered during // the read is also returned. // // EmptyPool is returned if additional storage is needed, but the buffer pool // is empty. It is possible for this to happen even when all of r is copied: // if the end of r coincides exactly with the end of the buffer's allocated // storage, and r doesn't immediately report its EOF, ReadFrom will try to // obtain additional storage from the pool before reading the EOF from r. io.ReaderFrom }
A variable-sized buffer whose backing storage is drawn from a fixed-sized pool. Clients must return the backing storage to the pool by calling Release.
Based on bytes.Buffer.
type BufferPool ¶
type BufferPool interface { // Returns a new empty buffer NewBuffer() Buffer }
A factory of variable-sized buffers whose backing storage is drawn from a fixed-sized pool. Clients must return the backing storage for all buffers obtained from this pool by calling Reset on the buffer.
func MakeBufferPool ¶
func MakeBufferPool(maxPoolSize_bytes int64, chunkSize_bytes int64) (BufferPool, error)
Creates a new buffer pool. Up to maxPoolSize_bytes of buffer chunks will be pooled. Each buffer chunk will have size chunkSize_bytes.