-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as duplicate of#13650
Labels
Milestone
Description
Proposal Details
Background
The bufio package currently only provides 2 APIs to create a new Writer
NewWriter(w io.Writer) *WriterNewWriterSize(w io.Writer, size int) *Writer
Problem
Both functions internally allocate a buffer, which may not be ideal for all use cases.
Motivation
There are scenarios where developers may want to manage buffer allocation themselves, such as using a sync.Pool of buffers or byte slices. In such cases, the current bufio APIs force a new buffer allocation each time a bufio.Writer is created, thus limiting the benefits of reusing buffers through a pool.
Proposal
Add a new function to the bufio package:
func NewWriterBuffer(w io.Writer, buf []byte) *WriterReactions are currently unavailable