Struct UnsafeSpan
Replacement for System.Span which is compatible with earlier versions of C#.
These spans do not in any way guarantee that the memory they refer to is valid. It is up to the user to make sure the memory is not deallocated before usage. It should never be used to refer to managed heap memory without pinning it, since unpinned managed memory can be moved by some runtimes.
This has several benefits over e.g. UnsafeList:
It is faster to index into a span than into an UnsafeList, especially from C#. In fact, indexing into an UnsafeSpan is as fast as indexing into a native C# array.
As a comparison, indexing into a NativeArray can easily be 10x slower, and indexing into an UnsafeList is at least a few times slower.
You can create a UnsafeSpan from a C# array by pinning it.
It can be sliced efficiently.
It supports ref returns for the indexing operations.
Public Methods
Copy the range [startIndex,startIndex+count) to [toIndex,toIndex+count)
Returns a new span with a different size, copies the current data over to it, and frees this span.
Public Variables
Number of elements in this span.