Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provide a way to reset an ArrayBufferWriter without clearing the underlying memory #49134

@john-h-k

Description

@john-h-k

Background and Motivation

Currently there is no way to reset an ArrayBufferWriter<T> without zeroing the underlying memory, which can be expensive and an entirely unnecessary cost often.

Proposed API

namespace System.Buffers
{
    public class ArrayBufferWriter<T> : IBufferWriter<T>
    {
+        public void Reset();
    }
}

Usage Examples

When building short-lived buffers in high performance scenarios (for example, to generate command buffers to be sent over PCIE or network to control physical devices), being able to quickly reset the buffer writer is helpful, and zeroing is an unnecessary expense.

Alternative Designs

It could alternatively be an overload of Clear:

public void Clear(bool zeroBackingArray);

Risks

Types which contain references should probably still be cleared to allow collection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions