Beskar.Memory
1.6.2
dotnet add package Beskar.Memory --version 1.6.2
NuGet\Install-Package Beskar.Memory -Version 1.6.2
<PackageReference Include="Beskar.Memory" Version="1.6.2" />
<PackageVersion Include="Beskar.Memory" Version="1.6.2" />
<PackageReference Include="Beskar.Memory" />
paket add Beskar.Memory --version 1.6.2
#r "nuget: Beskar.Memory, 1.6.2"
#:package Beskar.Memory@1.6.2
#addin nuget:?package=Beskar.Memory&version=1.6.2
#tool nuget:?package=Beskar.Memory&version=1.6.2
Beskar.Memory
A low-allocation, high-performance C# utility library designed to minimize GC pressure and maximize CPU-cache efficiency in hot execution paths. It provides high-performance ring buffers, lock-free object pools, hardware-accelerated bitsets, stack-safe buffer writers, and zero-allocation binary readers/writers.
Core Component Directory
1. Buffers & Writers
CircularBuffer<T>- Description: A high-performance, modulo-free ring buffer backed by
MemoryOwner<T>rented from a shared array pool. - Key Feature: Replaces slow division operations (
% Capacity) with ultra-fast conditional branch subtractions for maximum speed.
- Description: A high-performance, modulo-free ring buffer backed by
CircularBufferSlim<T>- Description: A lightweight, stack-allocated equivalent of
CircularBuffer<T>for short-lived scopes.
- Description: A lightweight, stack-allocated equivalent of
ByteReader- Description: A stack-only, zero-allocation
ref structsequence-aware reader. - Key Feature: Deserializes built-in C# types from contiguous
ReadOnlySpan<byte>or fragmentedReadOnlySequence<byte>arrays.
- Description: A stack-only, zero-allocation
ByteWriter- Description: A stack-only, zero-allocation
ref structwriter designed for writing bytes and binary data.
- Description: A stack-only, zero-allocation
BufferWriter<T>- Description: A premium, stack-only
ref structwriter that writes to an initial stack-allocated span and seamlessly grows onto rented array pool memory if capacity is exceeded.
- Description: A premium, stack-only
SpanOwner<T>- Description: A stack-safe unmanaged/rented buffer owner that wraps disposable array rents.
MemoryOwner<T>- Description: A heap-allocated rented memory block owner with automatic disposal lifecycle tracking.
2. Object Pooling
ObjectPool<T>- Description: A thread-safe, concurrent object recycler for heavy reuse scenarios.
- Key Feature: Features a lock-free fast-path head slot using
Interlocked.CompareExchange, completely bypassing queue contention.
DisposableObjectPool<T>- Description: A specialized object pool for objects implementing
IDisposable, ensuring proper element disposal upon pool cleanup or overflow.
- Description: A specialized object pool for objects implementing
AsyncDisposableObjectPool<T>- Description: A specialized object pool supporting objects implementing
IAsyncDisposablefor non-blocking asynchronous resource cleanup.
- Description: A specialized object pool supporting objects implementing
PinnedBlockMemoryPool- Description: A memory pool that allocates page-pinned memory blocks for advanced native interop.
IoQueue- Description: A high-performance task scheduling queue optimized for low-latency asynchronous IO completion.
3. Bitwise & Flags
PackedBools8/PackedBools16/PackedBools32/PackedBools64- Description: Struct wrappers packing boolean flags into integer primitives (
byte,ushort,uint,ulong). - Key Feature: Includes 1-cycle branchless range checks and hardware-accelerated set-bit counting via
BitOperations.PopCount.
- Description: Struct wrappers packing boolean flags into integer primitives (
Flags128/Flags256- Description: High-speed, fixed-size bitset structures backed by C# 12
[InlineArray(N)]attributes overPackedBools64chunks. - Key Feature: Division-free bitwise shifts for O(1) bit lookup across segment boundaries.
- Description: High-speed, fixed-size bitset structures backed by C# 12
4. Extensions
SpanByteReadExtensions- Description: Provides high-performance extension methods to read unmanaged types in big-endian and little-endian formats from byte spans, utilizing stackalloc reversions on endianness mismatch.
ByteWriteExtensions- Description: Provides high-performance extension methods to write unmanaged types in big-endian and little-endian formats directly into byte spans and buffer writers.
ServiceProviderExtensions- Description: Employs experimental C# 13
extensionblock syntax to resolve up to 8 generic services concurrently from anIServiceProvider.
- Description: Employs experimental C# 13
VoidResultExtensions- Description: Provides clean result mappings for void operations.
5. Results & Errors
Result<TSuccess, TError>- Description: A premium, lightweight, IEquatable union struct representing successful or failed operation results.
- Key Feature: Fully IEquatable, allocation-free deconstruction, and robust nullability protections to prevent string formatting crashes.
VoidResult<TError>- Description: An allocation-free union struct representing operations returning void that may fail.
Error/StringError- Description: Compact, readonly error-type wrappers designed for structured API responses.
6. Threading
WorkPool- Description: A premium, high-performance, bounded asynchronous actor/work pool queue backed by
System.Threading.Channels. - Key Feature: Fixed outer-task worker unwrapping concurrency bug to ensure reliable shutdown awaits.
- Description: A premium, high-performance, bounded asynchronous actor/work pool queue backed by
TaskExtensions- Description: Provides
WithAggregateExceptiontask helpers to preserve and unwrap exceptions across concurrent worker queues.
- Description: Provides
7. Timing
AsyncTimer- Description: A high-performance, stack-only
ref structtimer designed for asynchronous operation performance tracking.
- Description: A high-performance, stack-only
StackTimer- Description: A lightweight, stack-only timer for synchronous block profiling.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Beskar.Memory:
| Package | Downloads |
|---|---|
|
Beskar.Memory.Code.ObserveGenerator
Generates high-performance observability Activity, Meter, and Instrument extensions backed by Beskar.Memory. |
|
|
Beskar.Memory.Code.PacketGenerator
Generates high-performance packet serialization and routing extensions backed by Beskar.Memory. |
|
|
Beskar.Memory.Code
Useful extensions and utilities for Source Generators backed by Beskar.Memory. |
|
|
Beskar.Memory.Code.EnumGenerator
Generates high-performance enum helper extensions backed by Beskar.Memory. |
|
|
Beskar.Memory.Code.TypeIdGenerator
Generates implementation of record struct type safe ids backed by Beskar.Memory. |
GitHub repositories
This package is not used by any popular GitHub repositories.