IMemoryOwner<T> IMemoryOwner<T> IMemoryOwner<T> IMemoryOwner<T> Interface


識別記憶體區塊的擁有者,該擁有者負責妥善地處置基礎記憶體。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



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



IMemoryOwner<T>介面用來定義擁有者負責的存留期管理Memory<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.

因為IMemoryOwner<T>物件會實作IDisposable介面,您應該呼叫其Dispose方法不再需要的記憶體緩衝區,並已被終結時,才可以。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 Memory Memory Memory

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


Dispose() Dispose() Dispose() Dispose()

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

(Inherited from IDisposable)