Table of Contents

Class ExMemoryMarshal

Namespace
Zyl.ExSpans
Assembly
ExSpans.Core.dll

Provides a collection of methods for interoperating with ExSpan<T>, and ReadOnlyExSpan<T>. It can be regarded as the MemoryMarshal of nint index range (提供与 ExSpan 和 ExReadOnlySpan 互操作的方法. 它可以被视为 nint 索引范围的 MemoryMarshal).

public static class ExMemoryMarshal
Inheritance
ExMemoryMarshal
Inherited Members

Fields

ArrayMaxLengthSafe

The safe maximum length of array (安全的数组最大长度).

SpanViewLength

The length of the view span (查看跨度的长度).

Properties

Is64BitProcess

Gets a value that indicates whether the current process is a 64-bit process (获取一个值,该值指示当前进程是否为 64 位进程).

Methods

AsBytes<T>(ExSpan<T>)

Casts a ExSpan of one primitive type T to ExSpan of bytes. That type may not contain pointers or references. This is checked at runtime in order to preserve type safety (将一个基元类型T的ExSpan 转换为字节的ExSpan. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).

AsBytes<T>(ReadOnlyExSpan<T>)

Casts a ReadOnlyExSpan of one primitive type T to ReadOnlyExSpan of bytes. That type may not contain pointers or references. This is checked at runtime in order to preserve type safety. (将一个基元类型T的ExSpan 转换为字节的ReadOnlyExSpan. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).

AsRef<T>(ExSpan<byte>)

Re-interprets a span of bytes as a reference to structure of type T. The type may not contain pointers or references. This is checked at runtime in order to preserve type safety. (将字节跨度重新解释为对 T 类型结构体的引用. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).

AsRef<T>(ReadOnlyExSpan<byte>)

Re-interprets a read-only span of bytes as a reference to structure of type T. The type may not contain pointers or references. This is checked at runtime in order to preserve type safety. (将字节只读跨度重新解释为对 T 类型结构体的引用. 该类型不能包含指针或引用. 它会在运行时检查这一点, 以保护类型安全).

Cast<TFrom, TTo>(ExSpan<TFrom>)

Casts a ExSpan of one primitive type TFrom to another primitive type TTo. These types may not contain pointers or references. This is checked at runtime in order to preserve type safety. (将一种基元类型 TFrom的ExSpan 转换为另一种基元类型 TTo. 该类型不能包含指针或引用。它会在运行时检查这一点,以保护类型安全).

Cast<TFrom, TTo>(ReadOnlyExSpan<TFrom>)

Casts a ReadOnlyExSpan of one primitive type TFrom to another primitive type TTo. These types may not contain pointers or references. This is checked at runtime in order to preserve type safety. (将一种基元类型TFrom的 ReadOnlyExSpan 转换为另一种基元类型 TTo. 该类型不能包含指针或引用。它会在运行时检查这一点,以保护类型安全).

CreateExSpan<T>(scoped ref T, nint)

Creates a new 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).

CreateReadOnlyExSpanFromNullTerminated(byte*)

Creates a new read-only span for a null-terminated UTF-8 string (为 空终止UTF-8字符串 创建新的只读跨度).

CreateReadOnlyExSpanFromNullTerminated(char*)

Creates a new read-only span for a null-terminated string (为 空终止字符串 创建新的只读跨度).

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).

GetArrayDataReference<T>(T[])

Returns a reference to the 0th element of array. If the array is empty, returns a null reference. Such a reference may be used for pinning but must never be dereferenced (返回对 array 中第 0 个元素的引用。 如果数组为空,则返回对 null 引用。 此类引用可用于固定,但绝不能取消引用).

GetReference<T>(ExSpan<T>)

Returns a reference to the 0th element of the ExSpan. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced (返回 ExSpan 中索引为 0 处元素的引用. 这样的引用可能为空, 也可能不为空. 它可以用于固定, 但绝不能解引用).

GetReference<T>(ReadOnlyExSpan<T>)

Returns a reference to the 0th element of the ReadOnlyExSpan. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced (返回 ReadOnlyExSpan 中索引为 0 处元素的引用. 这样的引用可能为空, 也可能不为空. 它可以用于固定, 但绝不能解引用).

Read<T>(ReadOnlyExSpan<byte>)

Reads a structure of type T out of a read-only span of bytes (从字节的只读跨度中读取的 T 类型结构体).

TryRead<T>(ReadOnlyExSpan<byte>, out T)

Tries to read a structure of type T from a read-only span of bytes (尝试从字节的只读跨度中读取 T 类型结构体).

TryWrite<T>(ExSpan<byte>, in T)

Tries to write a structure of type T into a span of bytes (尝试将类型为 T 的结构体写入到字节的跨度中).

Write<T>(ExSpan<byte>, in T)

Writes a structure of type T into a span of bytes (将 T 类型的结构体写入字节跨度内).