I am trying to use ReadOnlySpan<T>, for decoding purpose. (here is initial question).
Regarding Microsoft documentation, I may find it in System.Runtime.dll
I checked and foud it in folder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades, but I still cannot use ReadOnlySpan.
Project is in .NET Framework 4.8
Is there something I am missing? Thanks
CodePudding user response:
Span<T> (and ReadOnlySpan<T>) were introduced in .NET Core 2.1, see this table. You can use it in .NET Framework by referencing the System.Memory NuGet package. Note however that this doesn't bring you quite the same speed improvements as using .NET Core 2.1 .
However, the code you're trying to use only has a single use of a span:
ReadOnlySpan<byte> bytes = stackalloc byte[] { (byte)(ch3 128) };
This is a cheap way to allocate an array on the stack, avoiding an object allocation. It's probably easier for you to just allocate an array here: with all of the other object allocations going on in that code, you won't notice the additional small cost:
byte[] bytes = new byte[] { (byte)(ch3 128) };
