Documentation ¶
Overview ¶
Package syncpool provides a non-leaky sync.Pool for github.com/klauspost/compress/zstd's Encoder and Decoder types, using wrappers (EncoderWrapper and DecoderWrapper).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDecoderPool ¶
NewDecoderPool returns a sync.Pool that provides DecoderWrapper objects, which embed *zstd.Decoders. You probably want to include zstd.WithDecoderConcurrency(1) in the list of options.
Types ¶
type DecoderPoolWrapper ¶ added in v0.0.11
type DecoderPoolWrapper struct {
// contains filtered or unexported fields
}
DecoderPoolWrapper is a convenience wrapper for sync.Pool which only accepts and returns *DecoderWrapper's.
func NewDecoderPoolWrapper ¶ added in v0.0.11
func NewDecoderPoolWrapper(options ...zstd.DOption) *DecoderPoolWrapper
NewDecoderPoolWapper returns a *DecoderPoolWrapper that provides *DecoderWrapper objects that do not need to be type asserted. As with NewDecoderPool, you probably want to include zstd.WithDecoderConcurrency(1) in the list of options.
func (*DecoderPoolWrapper) Get ¶ added in v0.0.11
func (d *DecoderPoolWrapper) Get(r io.Reader) *DecoderWrapper
Get returns a *DecoderWrapper that has been Reset to use r.
func (*DecoderPoolWrapper) Put ¶ added in v0.0.11
func (d *DecoderPoolWrapper) Put(w *DecoderWrapper)
Put returns a *DecoderWrapper to the pool.
type DecoderWrapper ¶
type DecoderWrapper struct { // *zstd.Decoder is not safe for use in a sync.Pool directly, since it // leaks data and goroutines. Finalizers on the *zstd.Decoder don't help // because the aforementioned goroutines reference the *zstd.Decoder and // prevent it from being garbage collected (so the finalizers don't run). // // We can work around this by storing this wrapper with an embedded // *zstd.Decoder in the sync.Pool, and using a finalizer on the wrapper // to Close the *zstd.Decoder. *zstd.Decoder // contains filtered or unexported fields }
DecoderWrapper is a wrapper that embeds a *zstd.Decoder, and is safe for use in a sync.Pool.
func (*DecoderWrapper) Close ¶
func (w *DecoderWrapper) Close()
Close does not close the embedded *zstd.Decoder (once closed, they cannot be reused), but instead resets it and places this *DecoderWrapper back in the pool.
func (*DecoderWrapper) IOReadCloser ¶
func (w *DecoderWrapper) IOReadCloser() io.ReadCloser
IOReadCloser returns an io.ReadCloser that will return this *DecoderWrapper to the pool when it is closed.
type EncoderPoolWrapper ¶ added in v0.0.11
type EncoderPoolWrapper struct {
// contains filtered or unexported fields
}
EncoderPoolWrapper is a convenience wrapper for sync.Pool which only accepts and returns *EncoderWrapper's.
func NewEncoderPoolWrapper ¶ added in v0.0.11
func NewEncoderPoolWrapper(options ...zstd.EOption) *EncoderPoolWrapper
NewEncoderPoolWapper returns an *EncoderPoolWrapper that provides *EncoderWrapper objects that do not need to be type asserted. As with NewEncoderPool, you probably want to include zstd.WithEncoderConcurrency(1) in the list of options.
func (*EncoderPoolWrapper) Get ¶ added in v0.0.11
func (e *EncoderPoolWrapper) Get(w io.Writer) *EncoderWrapper
Get returns an *EncoderWrapper that has been Reset to use w.
func (*EncoderPoolWrapper) Put ¶ added in v0.0.11
func (e *EncoderPoolWrapper) Put(w *EncoderWrapper)
Put returns an *EncoderWrapper to the pool.
type EncoderWrapper ¶
EncoderWrapper is a wrapper that embeds a *zstd.Encoder, and is safe for use in a sync.Pool.