CKTIS / C#
System.Buffers.IBufferWriter: riferimento pratico
System.Buffers.IBufferWriter: riferimento pratico: IBufferWriter<T> espone memoria scrivibile tramite GetSpan o GetMemory, mentre Advance conferma il numero esatto di elementi scritti.
Versione: .NET API; verified on .NET 10.0.14
Sintassi
System.Buffers.IBufferWriter /* select a documented member or constructor */IBufferWriter espone memoria scrivibile tramite GetSpan o GetMemory, mentre Advance conferma il numero esatto di elementi scritti.
Usalo in serializzatori e pipeline che producono dati progressivamente senza conoscere la dimensione finale.
Non conservare span o memory dopo una nuova richiesta e non avanzare oltre lo spazio effettivamente fornito.
Un sizeHint pari a zero è valido e un’implementazione può restituire una regione più grande del minimo richiesto.
Il programma completo usa realmente System.Buffers.IBufferWriter; lo stdout esatto atteso è 9.
Esempi
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
IBufferWriter<int> writer = new ArrayBufferWriter<int>();
var span = writer.GetSpan(1);
span[0] = 9;
writer.Advance(1);
Console.WriteLine(((ArrayBufferWriter<int>)writer).WrittenSpan[0]);
Risultato
9
Il programma completo usa realmente `System.Buffers.IBufferWriter`; lo stdout esatto atteso è `9`.