/ValueBuffer

The very fast, low memory, powerfull buffer for Stream, List, BufferWriter

Primary LanguageC#MIT LicenseMIT

ValueBuffer

The very fast, low memory, powerfull buffer for Stream, List, BufferWriter

.NET Quality Gate Status codecov

Useage

Using ValueList like List

using (var list = new ValueList<object>())
{
    for (int i = 0; i < Count; i++)
    {
        list.Add(obj);
    }
    list.ToArray();
}

Using ValueBufferMemoryStream for stream write and read

using (var mem = new ValueBufferMemoryStream())
{
    for (int j = 0; j < Count; j++)
    {
        mem.Add(value);
    }
    mem.Position = 0;
    mem.CopyTo(Stream.Null);
}

Using ValueListBufferWriter for Utf8JsonWriter

using (var w = new ValueListBufferWriter<byte>())
{
    using (var writer = new Utf8JsonWriter(w, new JsonWriterOptions { SkipValidation = true }))
    {
        WriterJson(writer);
    }
    w.List.WriteToStream(Stream.Null);
}

Using EncodingHelper for shared encoding

using (var buffer=EncodingHelper.SharedEncoding("hello"))
{
    Console.WriteLine(Encoding.UTF8.GetString(buffer.Span));//hello
}

Benchmarks

Benchmark