carlst99.MemoryReaders 1.0.0

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

// Install carlst99.MemoryReaders as a Cake Tool
#tool nuget:?package=carlst99.MemoryReaders&version=1.0.0                

MemoryReaders

Nuget | carlst99.MemoryReaders main codecov

The MemoryReaders package provides SequenceReader<T>-like APIs for Span<T> and Memory<T> instances, with a similar focus on performance and minimal-or-zero heap allocations.

The SpanReader<T> and MemoryReader<T> structures afford the ability to read and search Span/Memory instances in a forward-only manner (rewinding is supported).

MemoryReaders targets netstandard2.1.

Install

MemoryReaders is available on NuGet

dotnet add package carlst99.MemoryReaders

Usage

The SpanReader<T> can be constructed over any ReadOnlySpan<T> instance, and likewise for the MemoryReader<T>.

const string DataString = "The quick brown fox jumped over the lazy dog";

SpanReader<char> spanReader = new(DataString.AsSpan());
MemoryReader<char> memoryReader = new(DataString.AsMemory());

spanReader.TryReadTo
(
    out ReadOnlySpan<char> readData,
    delimiter: "fox".AsSpan(),
    advancePastDelimiter: false
);

bool foundQ = memoryReader.TryAdvanceTo('q', advancePastDelimiter: true);
if (foundQ && memoryReader.IsNext("uick".AsSpan()))
    Console.WriteLine("That was fast!");

Performance

MemoryReaders is not thoroughly benchmarked, but comparisons have been made between the SequenceReader, SpanReader and MemoryReader implementations for the IsNext, TryAdvanceTo and TryReadTo methods.

The results of benchmarking TryReadTo appear typical of the package, and are as follows:

// * Summary *

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
AMD Ryzen 5 3600, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.402
  [Host]     : .NET 6.0.10 (6.0.1022.47605), X64 RyuJIT
  DefaultJob : .NET 6.0.10 (6.0.1022.47605), X64 RyuJIT


|                  Method | Categories |      Mean |    Error |   StdDev | Ratio |
|------------------------ |----------- |----------:|---------:|---------:|------:|
|     UsingSequenceReader |  ShortData |  24.54 ns | 0.097 ns | 0.086 ns |  1.00 |
|       UsingMemoryReader |  ShortData |  17.30 ns | 0.051 ns | 0.042 ns |  0.71 |
|         UsingSpanReader |  ShortData |  15.02 ns | 0.017 ns | 0.015 ns |  0.61 |
|                         |            |           |          |          |       |
| UsingLongSequenceReader |   LongData | 139.89 ns | 0.637 ns | 0.565 ns |  1.00 |
|   UsingLongMemoryReader |   LongData | 131.52 ns | 0.863 ns | 0.721 ns |  0.94 |
|     UsingLongSpanReader |   LongData | 128.04 ns | 0.979 ns | 0.916 ns |  0.91 |
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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on carlst99.MemoryReaders:

Package Downloads
carlst99.Mandible

A library for working with the ForgeLight game engine's asset packs.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 563 11/12/2022

Initial Release.