Table of Contents

Method CreateReadOnlyExSpan

Namespace
Zyl.ExSpans
Assembly
ExSpans.Core.dll

CreateReadOnlyExSpan<T>(scoped ref readonly T, nint)

Creates a new read-only span over a portion of a regular managed object. This can be useful if part of a managed object represents a "fixed array." This is dangerous because the length is not checked (根据常规托管对象的一部分来创建新的只读跨度. 如果托管对象的一部分表示了 “固定数组”, 这可能会很有用. 这很危险, 因为不会检查 length).

public static ReadOnlyExSpan<T> CreateReadOnlyExSpan<T>(scoped ref readonly T reference, nint length)

Parameters

reference T

A reference to data (数据的引用).

length nint

The number of T elements the memory contains (存储里包含的 T 元素的数量).

Returns

ReadOnlyExSpan<T>

A read-only span representing the specified reference and length (表示了指定引用和长度的只读跨度).

Type Parameters

T

The element type (元素的类型).

Remarks

This method should be used with caution. It is dangerous because the length argument is not checked. Even though the ref is annotated as scoped, it will be stored into the returned span, and the lifetime of the returned span will not be validated for safety, even by span-aware languages (该方法应谨慎使用. 这种方法很危险, 因为它不会检查长度参数. 即使 ref 被申明为 scoped, 它也会存储在返回的跨度中, 而且返回的跨度的生命周期将不会进行安全验证, 即使是具有跨度意识的语言也是如此).