SpanOwner<T> Struct
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A stack-only type with the ability to rent a buffer of a specified length and getting a Span<T> from it. This type mirrors MemoryOwner<T> but without allocations and with further optimizations. As this is a stack-only type, it relies on the duck-typed IDisposable pattern introduced with C# 8. It should be used like so:
using (SpanOwner<byte> buffer = SpanOwner<byte>.Allocate(1024))
{
// Use the buffer here...
}
As soon as the code leaves the scope of that using
block, the underlying buffer will automatically
be disposed. The APIs in SpanOwner<T> rely on this pattern for extra performance, eg. they don't perform
the additional checks that are done in MemoryOwner<T> to ensure that the buffer hasn't been disposed
before returning a Memory<T> or Span<T> instance from it.
As such, this type should always be used with a using
block or expression.
Not doing so will cause the underlying buffer not to be returned to the shared pool.
public readonly ref struct SpanOwner<T>
type SpanOwner<'T> = struct
Public Structure SpanOwner(Of T)
- T
The type of items to store in the current instance.
- Inheritance
-
SpanOwner<T>
Empty |
Gets an empty SpanOwner<T> instance. |
Length |
Gets the number of items in the current instance |
Span |
Gets a Span<T> wrapping the memory belonging to the current instance. |
Allocate(Int32, Allocation |
Creates a new SpanOwner<T> instance with the specified parameters. |
Allocate(Int32, Array |
Creates a new SpanOwner<T> instance with the specified parameters. |
Allocate(Int32, Array |
Creates a new SpanOwner<T> instance with the specified parameters. |
Allocate(Int32) |
Creates a new SpanOwner<T> instance with the specified parameters. |
Dangerous |
Gets an ArraySegment<T> instance wrapping the underlying |
Dangerous |
Returns a reference to the first element within the current instance, with no bounds check. |
Dispose() |
Implements the duck-typed Dispose() method. |
To |
Returns the fully qualified type name of this instance. |
Produkt | Versioner |
---|---|
Windows Community Toolkit | 6.1.1, 7.0.0, 7.1.0 |