RentedListCore 0.2.3

dotnet add package RentedListCore --version 0.2.3
                    
NuGet\Install-Package RentedListCore -Version 0.2.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="RentedListCore" Version="0.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RentedListCore" Version="0.2.3" />
                    
Directory.Packages.props
<PackageReference Include="RentedListCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RentedListCore --version 0.2.3
                    
#r "nuget: RentedListCore, 0.2.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.
#:package RentedListCore@0.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RentedListCore&version=0.2.3
                    
Install as a Cake Addin
#tool nuget:?package=RentedListCore&version=0.2.3
                    
Install as a Cake Tool

RentedListCore

Disposable List structure allocating memory from ArrayPool

RentedListCore release RentedListCore download count

Usage

  • RentedList<T>: a disposable struct backed by ArrayPool<T>.Shared, with list operations, collection interfaces, and Span, Memory, and Segment views.
  • ValueRentedList<T>: a disposable ref struct that starts empty with a scratch Span<T> and switches to the pool when it outgrows it. Supports the same list operations and span views.
using RentedList<int> rented = [1, 2, 3];
rented.Add(4);

using var value = new ValueRentedList<int>(stackalloc int[4]);
value.AddRange(1, 2, 3, 4);
value.Add(5); // Grows into a rented array.

For both types, Clear() and Dispose() release storage and reset count/capacity to zero. Copies share storage; avoid disposing multiple copies or retaining views across growth or disposal.

Rented buffers

RentedBuffer<T> is a disposable struct for a fixed rental from ArrayPool<T>.Shared. The constructor accepts a minimum capacity; Capacity reports the actual rental size. Array, Span, Memory, and Segment expose the entire rental without copying. Implicit conversions are available to T[], Span<T>, ReadOnlySpan<T>, Memory<T>, ReadOnlyMemory<T>, and ArraySegment<T>, along with ref and range indexers.

using var buffer = new RentedBuffer<byte>(1024);
Span<byte> data = buffer;
data.Clear(); // Pooled storage is not guaranteed to be zeroed.
buffer[0] = 42;
Memory<byte> firstKilobyte = buffer.Memory[..1024];

Negative capacities throw; zero capacity and default buffers have empty views. Dispose() returns the rental and resets capacity to zero; repeated disposal of the same instance is harmless. Copies share storage, so dispose only one owner and stop using all borrowed views (including the array) before disposal. Arrays are returned without clearing their contents.

Stack-or-pool buffers

ValueRentedBuffer<T> is a disposable ref struct for a fixed buffer. Its constructor accepts a minimum capacity and an optional scratch Span<T>. It borrows the entire scratch span if large enough; otherwise it rents directly from ArrayPool<T>.Shared, without copying or modifying the scratch storage. There is no growth.

Allocate stack storage conditionally in the caller so larger requests rent without executing a stack allocation:

ArgumentOutOfRangeException.ThrowIfNegative(length);

const int StackLimit = 1024; // Bytes, since T is byte.
using var buffer = new ValueRentedBuffer<byte>(
    length,
    length <= StackLimit ? stackalloc byte[length] : default);

Span<byte> data = buffer.Span[..length];
data.Clear(); // Storage is not guaranteed to be zeroed.

Stack storage must be allocated in the caller's scope; a constructor or factory cannot return a buffer referencing its own stackalloc storage. Choose stack limits in bytes, accounting for the element size. T is unconstrained, but stackalloc requires unmanaged elements; reference types can use array-backed scratch spans or rentals. Omitting the scratch span rents directly for positive capacities.

Capacity and Span expose the entire selected storage, potentially larger than requested. Ref and range indexers and implicit conversions to Span<T> and ReadOnlySpan<T> share that storage. Negative capacities throw; zero capacity, even with scratch storage, and default buffers have empty views.

Dispose() returns only owned rentals, without clearing their contents, and resets the buffer to empty. Repeated disposal of the same instance is harmless. Copies share storage: dispose only one owner and stop using borrowed views before disposal. Caller-owned scratch storage remains owned by the caller.

Benchmarks

Adding elements

Code

Results

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
List_Add 797.3 ns 185.45 ns 10.17 ns 1.00 0.02 0.4473 0.0076 8424 B 1.00
RentedList_Add 516.5 ns 61.73 ns 3.38 ns 0.65 0.01 0.2174 0.0029 4120 B 0.49
RentedList_Add_Dispose 467.9 ns 55.01 ns 3.02 ns 0.59 0.01 - - - 0.00

Enumerating elements

Code

Results

Method Mean Error StdDev Ratio
Array_Enumerator 1.770 us 0.0873 us 0.0048 us 1.00
List_Enumerator 2.506 us 0.2307 us 0.0126 us 1.42
RentedList_Enumerator 2.364 us 0.4903 us 0.0269 us 1.34

Indexing elements

Code

Results

Method Mean Error StdDev Ratio RatioSD
Array_Indexer 1.793 us 0.4019 us 0.0220 us 1.00 0.02
List_Indexer 2.650 us 0.1405 us 0.0077 us 1.48 0.02
RentedList_Indexer 1.915 us 0.0873 us 0.0048 us 1.07 0.01

Creating collection

Code

Results

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Array_Create 119.7 ns 23.92 ns 1.31 ns 1.00 0.01 0.2136 - 3.93 KB 1.00
List_Create 130.5 ns 45.66 ns 2.50 ns 1.09 0.02 0.2153 0.0031 3.96 KB 1.01
RentedList_Create 250.2 ns 23.45 ns 1.29 ns 2.09 0.02 0.4325 0.0067 7.95 KB 2.02
RentedList_Create_Dispose 146.4 ns 42.75 ns 2.34 ns 1.22 0.02 0.2136 - 3.93 KB 1.00
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 is compatible.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 RentedListCore:

Package Downloads
DnsCore

.NET lightweight DNS server & client

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.3 75 9/14/2026
0.2.2 76 9/14/2026
0.2.1 84 9/13/2026
0.2.0 79 9/11/2026
0.1.6 1,124 7/1/2025
0.1.5 229 7/1/2025
0.1.4 258 3/28/2025
0.1.3 364 3/23/2025
0.1.2 360 3/23/2025
0.1.1 236 3/20/2025
0.1.0 278 3/11/2025