IMemoryOwner<T> 介面

定義

識別記憶體區塊的擁有者,該擁有者負責妥善地處置基礎記憶體。Identifies the owner of a block of memory who is responsible for disposing of the underlying memory appropriately.

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

要儲存在記憶體中的元素類型。The type of elements to store in memory.

衍生
實作

備註

介面是用來定義負責Memory<T>緩衝區之存留期管理的擁有者。 IMemoryOwner<T>The IMemoryOwner<T> interface is used to define the owner responsible for the lifetime management of a Memory<T> buffer. IMemoryOwner<T>介面的實例是MemoryPool<T>.Rent由方法傳回。An instance of the IMemoryOwner<T> interface is returned by the MemoryPool<T>.Rent method.

雖然緩衝區可以有多個取用者, 但在任何指定時間只能有一個擁有者。While a buffer can have multiple consumers, it can only have a single owner at any given time. 擁有者可以:The owner can:

  • 直接或藉由呼叫 factory 方法來建立緩衝區。Create the buffer either directly or by calling a factory method.

  • 將擁有權轉移給另一個取用者。Transfer ownership to another consumer. 在此情況下, 先前的擁有者應該不會再使用緩衝區。In this case, the previous owner should no longer use the buffer.

  • 當緩衝區不再使用時, 將其損毀。Destroy the buffer when it is no longer in use.

由於物件會實作為IDisposable介面, 因此只有在不再Dispose需要記憶體緩衝區, 而且您已將它終結之後, 才應該呼叫其方法。 IMemoryOwner<T>Because the IMemoryOwner<T> object implements the IDisposable interface, you should call its Dispose method only after the memory buffer is no longer needed and you have destroyed it. 應該處置IMemoryOwner<T>物件, 同時可以參考其記憶體。You should not dispose of the IMemoryOwner<T> object while a reference to its memory is available. 這表示宣告的類型IMemoryOwner<T>不應該Finalize有方法。This means that the type in which IMemoryOwner<T> is declared should not have a Finalize method.

屬性

Memory

取得屬於此擁有者的記憶體。Gets the memory belonging to this owner.

方法

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(繼承來源 IDisposable)

適用於