Salar.BinaryBuffers 3.1.0

.NET 6.0 .NET Standard 2.0
dotnet add package Salar.BinaryBuffers --version 3.1.0
NuGet\Install-Package Salar.BinaryBuffers -Version 3.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Salar.BinaryBuffers" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Salar.BinaryBuffers --version 3.1.0
#r "nuget: Salar.BinaryBuffers, 3.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Salar.BinaryBuffers as a Cake Addin
#addin nuget:?package=Salar.BinaryBuffers&version=3.1.0

// Install Salar.BinaryBuffers as a Cake Tool
#tool nuget:?package=Salar.BinaryBuffers&version=3.1.0




BinaryBuffers offers a highly performant implementation of BinaryReader and BinaryWriter, working directly on a byte array, thus eliminating the need for an intermediate Stream object.

How to use

BinaryBufferReader and BinaryBufferWriter are the respective names of the reader and writer. Both classes operate on a byte[] as its underlying data buffer.

// Provide a buffer to the reader/writer
var buffer = new byte[100];

// Write to the buffer
var writer = new BinaryBufferWriter(buffer);


// Read from the buffer
var reader = new BinaryBufferReader(buffer);

var year = reader.ReadInt32();
var time = reader.ReadDouble();

Additional Goodies

Use StreamBufferWriter as a drop in replacement for BinaryWriter to gain ~10% improvement in performance.

Use StreamBufferReader as a drop in replacement for BinaryReader. Note that there is no performance benefit in using StreamBufferReader, it just helps widen the use of IBufferReader.

Use ResetBuffer method in BinaryBufferReader and BinaryBufferWriter instead of creating a new one and have less allocations!


Benchmarks shows up to 75% improvement in writing and 32% in reading.

Method Mean Error StdDev Ratio
BinaryReader_ReadInt 38.96 ms 0.198 ms 0.185 ms baseline
BufferReader_ReadInt 26.51 ms 0.125 ms 0.104 ms -32%
BinaryReader_ReadDecimal 45.29 ms 0.169 ms 0.158 ms baseline
BufferReader_ReadDecimal 43.49 ms 0.296 ms 0.247 ms -4%
BinaryReader_ReadFloat 22.66 ms 0.049 ms 0.044 ms baseline
BufferReader_ReadFloat 15.91 ms 0.071 ms 0.067 ms -30%
Method Mean Error StdDev Ratio
BinaryWriter_WriteInt 66.98 ms 0.143 ms 0.119 ms baseline
BufferWriter_WriteInt 16.98 ms 0.339 ms 0.333 ms -75%
BinaryWriter_WriteDecimal 42.29 ms 0.108 ms 0.096 ms baseline
BufferWriter_WriteDecimal 18.49 ms 0.050 ms 0.047 ms -56%
BinaryWriter_WriteFloat 34.86 ms 0.494 ms 0.462 ms baseline
BufferWriter_WriteFloat 11.33 ms 0.076 ms 0.071 ms -67%

Performance tests were generated using .NET 6.0.11 on:

AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0 195 11/30/2022
3.0.1 188 11/27/2022
3.0.0 184 11/26/2022
2.0.0 295 7/30/2022
1.1.0 2,024 9/30/2019
1.0.0 413 8/29/2019

* Improved the performance of the readers.
* Improved the performance of the writer by unmarking methods as virtual.
* Improved the performance of the `BinaryBufferWriter` by using Spans.
* Added `StreamBufferWriter` as a drop in replacement for `BinaryWriter` to gain 5~10% improvement in performance.
* Added `BufferReaderBase` as the base of readers.
* Added `StreamBufferReader` as a drop in replacement for `BinaryReader` and to widen the support of input types.
* Added `ResetBuffer` to `BinaryBufferReader` which is to reset the underlying buffer and helps reuse `BinaryBufferReader` instead of creating a new one.
* Also added `ResetBuffer` to `BinaryBufferWriter`.
* Assemblies have strong name now.