FixedSizeBuffers 0.4.3

dotnet add package FixedSizeBuffers --version 0.4.3                
NuGet\Install-Package FixedSizeBuffers -Version 0.4.3                
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="FixedSizeBuffers" Version="0.4.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FixedSizeBuffers --version 0.4.3                
#r "nuget: FixedSizeBuffers, 0.4.3"                
#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 FixedSizeBuffers as a Cake Addin
#addin nuget:?package=FixedSizeBuffers&version=0.4.3

// Install FixedSizeBuffers as a Cake Tool
#tool nuget:?package=FixedSizeBuffers&version=0.4.3                

FixedSizeBuffers

A collection of fixed-size structs which can be treated as Spans. A replacement for stackalloc (or fixed-size buffers), but these buffers can contain reference types (and can't be dynamically sized).

void Copy(TextReader reader, TextWriter writer)
{
    // Allocate 2kB on the stack
    var buffer = new FixedSizeBuffer1024<char>();
    var span = buffer.AsSpan();

    var count = -1;
    while (count != 0)
    {
        count = reader.Read(span);
        writer.Write(span.Slice(count));
    }
    
    buffer.Dispose();
}

Buffers are provided in powers-of-two lengths, from 2 to 8192.

I hope you know what you're doing

Use of this library is potentially unsafe. When calling AsSpan or AsReadOnlySpan, you must make sure the Span doesn't outlive the FixedSizeBuffer. Basically, don't return the Span.

Span<int> Bad()
{
    var buffer = new FixedSizeBuffer4<int>();
    return buffer.AsSpan();  // Don't do this
}

You can safely pass around spans into buffers which live on the heap — but if you're doing that you might as well use an array.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FixedSizeBuffers:

Package Downloads
Sawmill

Simple tools for working with immutable trees, developed at Stack Overflow

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.3 291 11/28/2023
0.4.1 3,235 11/25/2021
0.3.0 359 5/10/2021
0.2.0 69,805 6/23/2020
0.1.0 499 5/4/2020