Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add ArrayPoolBufferWriter<T>.ResetWrittenCount()

Abierto
#1,051 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
42/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
performance

Línea de trabajo

Localiza la implementación de ArrayPoolBufferWriter y sus pruebas existentes. Añade el comportamiento público de ResetWrittenCount() descrito en el issue, verifica que el recuento de elementos escritos se restablece sin borrar ni reemplazar el búfer del pool y ejecuta la suite de pruebas pertinente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C#
Estrellas
3.8k
Forks
401
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CommunityToolkit/dotnet

Todos los issues de CommunityToolkit/dotnet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.