IMemoryOwner<T> 接口

定义

标识负责适当释放基础内存的内存块的所有者。

generic <typename T>
public interface class IMemoryOwner : IDisposable
public interface IMemoryOwner<T> : IDisposable
type IMemoryOwner<'T> = interface
    interface IDisposable
Public Interface IMemoryOwner(Of T)
Implements IDisposable

类型参数

T

要存储在内存中的元素的类型。

派生
实现

注解

IMemoryOwner<T> 接口用于定义负责缓冲区生存期管理的 Memory<T> 所有者。 方法返回IMemoryOwner<T>接口的MemoryPool<T>.Rent实例。

虽然缓冲区可以有多个使用者,但它在任何给定时间只能有一个所有者。 所有者可以:

  • 直接创建缓冲区,或通过调用工厂方法创建缓冲区。

  • 将所有权转让给另一个使用者。 在这种情况下,以前的所有者不应再使用缓冲区。

  • 在不再使用缓冲区时销毁缓冲区。

IMemoryOwner<T>由于对象实现IDisposable接口,因此应仅在不再需要内存缓冲区且已销毁该接口之后调用其Dispose方法。 当对对象的内存的引用可用时,不应释放IMemoryOwner<T>该对象。 这意味着声明的类型 IMemoryOwner<T> 不应具有方法 Finalize

属性

名称 说明
Memory

获取属于此所有者的内存。

方法

名称 说明
Dispose()

执行与释放、释放或重置非托管资源关联的应用程序定义任务。

(继承自 IDisposable)

适用于