You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This API is an abstraction and a singleton implementation of a pool providing OwnedMemory instances. The pool is used by (and required by) Pipelines, but is a very general purpose type.
The default implementation of the pool (MemoryPool<T>.Default) is using ArrayPool to provide actual memory buffers. Pipelines use an internal slab allocator implementation. There are other prototype implementations in corefxlab, e.g. NativeMemoryPool<T>; a pool based on native memory.
MemoryPool would go into System.Memory.dll and System.Buffers namespace
The pooled instances are returned to the pool when they are disposed:
using(OwnedMemory<byte>om=MemoryPool<byte>.Default.Rent()){Memory<byte>memory=om.Memory;Span<byte>span=memory.Span;
...}// this is where the om is returned to the pool
Minimum size. The sentinel of int.MinValue seems over the top, -1 seesm good enough. 1 would be too harsh, as the semantics we want is "give me any buffer size that is convenient for the pool".
Finalizer. Don't define a finalizer. Otherwise, all derived types (even the fully managed ones) go into the finalizer queue.
Default. Renamed to Shared to align with ArrayPool<T>.
Dispose. What should Dispose do for the Shared instance? It seems no-op is the best choice, otherwise everyone has to special case when folks.
This API is an abstraction and a singleton implementation of a pool providing OwnedMemory instances. The pool is used by (and required by) Pipelines, but is a very general purpose type.
The default implementation of the pool (
MemoryPool<T>.Default
) is using ArrayPool to provide actual memory buffers. Pipelines use an internal slab allocator implementation. There are other prototype implementations in corefxlab, e.g.NativeMemoryPool<T>
; a pool based on native memory.MemoryPool would go into System.Memory.dll and System.Buffers namespace
The pooled instances are returned to the pool when they are disposed:
cc: @davidfowl, @pakrym, @joshfree, @ahsonkhan
The text was updated successfully, but these errors were encountered: