Skip to content

proposal: bufio: introduce a NewWriterBuffer #69970

@ahmedabdou14

Description

@ahmedabdou14

Proposal Details

Background

The bufio package currently only provides 2 APIs to create a new Writer

  • NewWriter(w io.Writer) *Writer
  • NewWriterSize(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) *Writer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions