RentedMemory 1.1.0

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

// Install RentedMemory as a Cake Tool
#tool nuget:?package=RentedMemory&version=1.1.0

RentedMemory

RentedMemory is a library that builds on ArrayPool to make it explicit that you are using a rented array and adds some functionality.

Includes:

  • RentedMemory is a readonly struct wrapper around ArrayPool used kinda like dispose pattern.
  • RentedMemoryBuilder is a StringBuilder alternative with zero allocation (pooled) and works on any struct.
  • RentedObjects is a lightweight objectpool where you create the objects yourself.

Nuget Package

Getting Started

RentedMemory

// Rent a array of bytes with MinimumSize 24
var Rented = RentedMemory<byte>.Rent(MinimumSize: 24);

//Return it when you dont need it anymore
Rented.Return();

RentedMemoryBuilder

// Rent a array of char with MinimumSize 2
var RentedString = RentedMemoryBuilder<char>.Rent(MinimumSize: 2);

//RentedMemoryBuilder will grow if needed, still using ArrayPool
RentedString.Append("Hello World");
RentedString.Prepend("Hello World");
RentedString.Insert("Hello World");
RentedString.Replace("Hello World", "Hello");
RentedString.Remove("Hello");

//Write to the Span if you want full control, just remember to EnsureSize
RentedString.EnsureSize(FileLength)
int WrittenText = ReadTextFile(RentedString.RemainingSpan);
RentedString.AdvanceRemaining(WrittenText);

//Get the WrittenSpan or WrittenMemory when done and copy it somewhere, then return it
RentedString.WrittenSpan;
RentedString.WrittenMemory;
RentedString.Return();

//Or get the internal RentedMemory out when you are done building and ready to return the builder
RentedString.Return(out RentedMemory<char> RentedArray);

RentedObjects

// Create a new RentedObjects of objects
RentedObjects = new RentedObjects<object>(MaxPooledItemsSize: 16);

//Rents a object or returns null so you can create a new one
//object Object = RentedObjects.Rent() ?? new object();
object? Object = RentedObjects.Rent();

if(Object is null)
    Object = new object();

//Return it when you dont need it anymore
RentedObjects.Return(Object);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 413 8/4/2022
1.0.4 365 7/30/2022
1.0.3 383 7/25/2022
1.0.2-alpha 132 7/24/2022
1.0.1 369 7/24/2022
1.0.0 364 7/24/2022