Generic fixed size buffers.
Deprecated Package Version
Reason: Legacy
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.
Get Started
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard | |
| Other |
README
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.
Downloads by Version
Similar & Alternative Packages
Hand-picked matching NuGet libraries based on tags & ecosystem
Depended On By
Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.