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

Add segmented buffering and sequence reads to `ArrayPoolBufferWriter<T>`

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

@paulomorgado がすでに取り組んでいます。

2026年9月27日 から。

  • #1216 @paulomorgado による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp

調査の方向性

Start by inspecting the existing ArrayPoolBufferWriter implementation, especially GetSpan(), GetMemory(), WrittenMemory, WrittenSpan, DangerousGetArray(), Clear(), and Dispose(). Compare the proposed segmented behavior with the feature/segmented-arraypoolbufferwriter branch. Done means adding GetReadOnlySequence(), retaining completed pooled arrays, consolidating contiguous views on demand, and returning all arrays during cleanup.

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

説明

feature request :mailbox_with_mail:
Overview

ArrayPoolBufferWriter<T> currently copies all written data into a new pooled array whenever it grows. With multiple writes and an unknown final size, those repeated copies consume memory bandwidth. Retaining completed arrays as segments would avoid copying earlier writes on each growth and let callers read the result as a ReadOnlySequence<T> without flattening it. Callers that need a contiguous buffer could still use the existing APIs, which would consolidate on demand.

API breakdown
namespace CommunityToolkit.HighPerformance.Buffers;

public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
{
    public ReadOnlySequence<T> GetReadOnlySequence();
}

Existing public signatures remain unchanged. GetSpan() and GetMemory() write to the active segment; WrittenMemory, WrittenSpan, and DangerousGetArray() provide contiguous data through on-demand consolidation. Clear() and Dispose() return retained arrays to the pool. A returned sequence is valid only until the writer is modified, consolidated, cleared, or disposed.

Usage example
using ArrayPoolBufferWriter<byte> writer = new();

foreach (ReadOnlyMemory<byte> chunk in chunks)
{
    chunk.Span.CopyTo(writer.GetSpan(chunk.Length));
    writer.Advance(chunk.Length);
}

// Consume the segments while the writer still owns their pooled arrays.
foreach (ReadOnlyMemory<byte> segment in writer.GetReadOnlySequence())
{
    destination.Write(segment.Span);
}
Breaking change?

I'm not sure

Alternatives

Keep the current contiguous writer and pay the copy cost on growth, or use Microsoft.IO.RecyclableMemoryStream where its MemoryStream-like API and pooling features are needed.

Additional context

This may be slower for some workloads. Segmentation adds buffer rents and metadata, while requesting a contiguous view still requires a copy. Small payloads and code that frequently accesses WrittenMemory or WrittenSpan should be benchmarked alongside append-heavy workloads.

Combined with other CommunityToolkit.HighPerformance memory and stream helpers, this might be a good alternative to Microsoft.IO.RecyclableMemoryStream for some append-and-read workloads. It would not be a drop-in replacement for that library’s seekable stream behavior, configurable pooling, or diagnostics. A proposed implementation is in feature/segmented-arraypoolbufferwriter.

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 を短くまとめたダイジェスト。