Struct UnsafeSpan
Replacement for System.Span which is compatible with earlier versions of C#.
Warning
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
Creates a new copy of the span allocated using the given allocator.
Copies the memory of this span to another span.
Appends all elements in this span to the given list.
Frees the underlaying memory.
Copy the range [startIndex,startIndex+count) to [toIndex,toIndex+count)
Returns a copy of this span, but with a different data-type.
Creates a new span which is a slice of this span.
Creates a new span which is a slice of this span.
Converts the span to a managed array.
Public Variables
Number of elements in this span.