Class UnmanagedMemoryPool<T>
Represents pool of unmanaged memory,
Namespace: DotNext.Buffers
Assembly: DotNext.Unsafe.dll
Syntax
public sealed class UnmanagedMemoryPool<T> : MemoryPool<T> where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of the items in the memory pool. |
Constructors
| Improve this Doc View SourceUnmanagedMemoryPool(Int32, Int32, Boolean)
Initializes a new pool of unmanaged memory.
Declaration
public UnmanagedMemoryPool(int maxBufferSize, int defaultBufferSize = 32, bool trackAllocations = false)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxBufferSize | The maximum allowed number of elements that can be allocated by the pool. |
Int32 | defaultBufferSize | The default number of elements that can be allocated by the pool. |
Boolean | trackAllocations | true to release allocated unmanaged memory when Dispose(Boolean) is called; otherwise, false. |
Properties
| Improve this Doc View SourceMaxBufferSize
Gets the maximum elements that can be allocated by this pool.
Declaration
public override int MaxBufferSize { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceAllocate(Int32, Boolean)
Allocates unmanaged memory and returns an object that controls its lifetime.
Declaration
public static IUnmanagedMemoryOwner<T> Allocate(int length, bool zeroMem = true)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The number of elements to be allocated in unmanaged memory. |
Boolean | zeroMem | true to set all bits in the memory to zero; otherwise, false. |
Returns
Type | Description |
---|---|
IUnmanagedMemoryOwner<T> | The object representing allocated unmanaged memory. |
Dispose(Boolean)
Frees the unmanaged resources used by the memory pool and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Rent(Int32)
Returns unmanaged memory block capable of holding at least length
elements of T
.
Declaration
public override IMemoryOwner<T> Rent(int length = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The length of the continuous block of memory. |
Returns
Type | Description |
---|---|
IMemoryOwner<T> | The allocated block of unmanaged memory. |