FixedSizeBuffers 0.4.3
DEPRECATED: This library is no longer recommended. Since .NET 8, you can use inline arrays (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-12.0/inline-arrays) which serve the same purpose as this library but are officially supported by the runtime and guaranteed to work across all platforms.
dotnet add package FixedSizeBuffers --version 0.4.3
NuGet\Install-Package FixedSizeBuffers -Version 0.4.3
<PackageReference Include="FixedSizeBuffers" Version="0.4.3" />
<PackageVersion Include="FixedSizeBuffers" Version="0.4.3" />
<PackageReference Include="FixedSizeBuffers" />
paket add FixedSizeBuffers --version 0.4.3
#r "nuget: FixedSizeBuffers, 0.4.3"
#:package FixedSizeBuffers@0.4.3
#addin nuget:?package=FixedSizeBuffers&version=0.4.3
#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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETCoreApp 3.1
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
-
net5.0
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
-
net8.0
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.