The very fast, low memory, powerfull buffer for Stream, List, BufferWriter
using (var list = new ValueList<object>())
{
for (int i = 0; i < Count; i++)
{
list.Add(obj);
}
list.ToArray();
}
using (var mem = new ValueBufferMemoryStream())
{
for (int j = 0; j < Count; j++)
{
mem.Add(value);
}
mem.Position = 0;
mem.CopyTo(Stream.Null);
}
using (var w = new ValueListBufferWriter<byte>())
{
using (var writer = new Utf8JsonWriter(w, new JsonWriterOptions { SkipValidation = true }))
{
WriterJson(writer);
}
w.List.WriteToStream(Stream.Null);
}
using (var buffer=EncodingHelper.SharedEncoding("hello"))
{
Console.WriteLine(Encoding.UTF8.GetString(buffer.Span));//hello
}