Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add ArrayPoolBufferWriter<T>.ResetWrittenCount()

オープン
#1,051 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
csharp
領域
performance

調査の方向性

ArrayPoolBufferWriter の実装と既存のテストを見つけてください。Issue に記載されている ResetWrittenCount() の public な動作を追加し、プールされたバッファーをクリアまたは置き換えることなく書き込み済みカウントがリセットされることを確認して、関連するテストスイートを実行してください。

索引モデルが issue の本文から書いたものです。

説明

feature request :mailbox_with_mail:
Overview

The System.Buffers.ArrayBufferWriter<T> class has a ResetWrittenCount method, which resets the write position to zero without clearing the buffer, thus allowing a writer to be reused without clearing the buffer. Without this method, we must create a new ArrayPoolBufferWriter<T> instance each time, which carries the GC overhead of allocating the new object, but also the overhead of returning the buffer to the pool, only to immediately get it back again.

API breakdown
namespace CommunityToolkit.HighPerformance.Buffers;

public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
{
    public void ResetWrittenCount() => index = 0;
}
Usage example
using var buffer = new ArrayPoolBufferWriter<byte>();
using var jsonWriter = new Utf8JsonWriter(buffer);

for (var i = 0; i < 100; i++)
{
    // Serialize JSON into buffer.
    JsonSerializer.Serialize(jsonWriter, obj, _jsonOptions);

    // Compress JSON into output buffer.
    compressionStream.Write(buffer.WrittenSpan);

    // Reset the JSON writer and buffer.
    buffer.ResetWrittenCount();
    jsonWriter.Reset();
}
Breaking change?

No

Alternatives

There is no way to reuse the buffer without incurring the cost of clearing the buffer or cycling the buffer through the array pool.

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

主要言語
C#
スター
3.8k
フォーク
401
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommunityToolkit/dotnet のほかの issue

CommunityToolkit/dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。