C# Span versus aux::slice

The Span<T> has landed in .NET Standard today.

According to the article

(Span<T> is) at the heart of most performance-related improvements in .NET Core 2.1. Since it allows managing buffers in a more efficient way, it can help in reducing allocations and copying. We consider Span to be a very fundamental type as it requires runtime and compiler support in order to be fully leveraged.

The Span is a simple struct with two fields and methods:

public readonly ref struct Span<T>
  private readonly ref T _pointer;
  private readonly int _length;

And that’s exactly what Sciter Engine uses for the same purpose from the very beginning, so 10+ years so far:

template <typename T>
   struct slice
      const T*       start;
      unsigned int   length;

It uses this construct as internally everywhere as in SDK.

Nothing new under the Sun …

Leave a Reply

Your email address will not be published. Required fields are marked *