Documentation ¶
Overview ¶
Package bufferpool implements a pool of reusable auto-resizing buffers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(size int) tank
New instantiates a new bytes.Buffer pool with a custom pre-allocated buffer size.
func NewTwin ¶
func NewTwin(size int) twinTank
NewTwin instantiates a new TwinBuffer pool with a custom pre-allocated buffer size. The fields `First` and `Second` will have the same size.
func Put ¶
Put returns a buffer to the pool. The buffer is reset before it is put back into circulation.
func PutReader ¶
Put returns a byte reader to the pool. The reader is reset before it is put back into circulation.
func PutTwin ¶
func PutTwin(buf *TwinBuffer)
PutTwin returns a twin buffer to the pool. The buffers get reset before they are put back into circulation.
func PutTwinCallBack ¶
func PutTwinCallBack(buf *TwinBuffer, fn func())
PutTwinCallBack same as PutTwin but executes fn after buf has been returned into the pool.
buf := twinBuf.Get() defer twinBuf.PutCallBack(buf, wg.Done)
Types ¶
type TwinBuffer ¶
TwinBuffer contains two buffers.
func GetTwin ¶
func GetTwin() *TwinBuffer
GetTwin returns a buffer containing two buffers, `First` and `Second`, from the pool.
func (*TwinBuffer) CopyFirstToSecond ¶
func (tw *TwinBuffer) CopyFirstToSecond() (n int64, err error)
CopyFirstToSecond resets the second buffer and copies the content from the first buffer to the second buffer. First buffer gets eventually reset.
func (*TwinBuffer) CopySecondToFirst ¶
func (tw *TwinBuffer) CopySecondToFirst() (n int64, err error)
CopySecondToFirst resets the first buffer and copies the content from the second buffer to the first buffer. Second buffer gets eventually reset.
func (*TwinBuffer) String ¶
func (tw *TwinBuffer) String() string
String prints the buffers content for debug purposes.