Class ArrayPoolMemoryAllocator
Contains SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.Buffer`1 and SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.ManagedByteBuffer.
Inherited Members
Namespace: SixLabors.ImageSharp.Memory
Assembly: SixLabors.ImageSharp.dll
Syntax
public sealed class ArrayPoolMemoryAllocator : MemoryAllocator
Constructors
| Improve this Doc View SourceArrayPoolMemoryAllocator()
Initializes a new instance of the ArrayPoolMemoryAllocator class.
Declaration
public ArrayPoolMemoryAllocator()
ArrayPoolMemoryAllocator(Int32)
Initializes a new instance of the ArrayPoolMemoryAllocator class.
Declaration
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxPoolSizeInBytes | The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. |
ArrayPoolMemoryAllocator(Int32, Int32)
Initializes a new instance of the ArrayPoolMemoryAllocator class.
Declaration
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxPoolSizeInBytes | The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. |
Int32 | poolSelectorThresholdInBytes | Arrays over this threshold will be pooled in SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.largeArrayPool which has less buckets for memory safety. |
ArrayPoolMemoryAllocator(Int32, Int32, Int32, Int32)
Initializes a new instance of the ArrayPoolMemoryAllocator class.
Declaration
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes, int maxArraysPerBucketLargePool, int maxArraysPerBucketNormalPool)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxPoolSizeInBytes | The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. |
Int32 | poolSelectorThresholdInBytes | The threshold to pool arrays in SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.largeArrayPool which has less buckets for memory safety. |
Int32 | maxArraysPerBucketLargePool | Max arrays per bucket for the large array pool. |
Int32 | maxArraysPerBucketNormalPool | Max arrays per bucket for the normal array pool. |
ArrayPoolMemoryAllocator(Int32, Int32, Int32, Int32, Int32)
Initializes a new instance of the ArrayPoolMemoryAllocator class.
Declaration
public ArrayPoolMemoryAllocator(int maxPoolSizeInBytes, int poolSelectorThresholdInBytes, int maxArraysPerBucketLargePool, int maxArraysPerBucketNormalPool, int bufferCapacityInBytes)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxPoolSizeInBytes | The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated. |
Int32 | poolSelectorThresholdInBytes | The threshold to pool arrays in SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.largeArrayPool which has less buckets for memory safety. |
Int32 | maxArraysPerBucketLargePool | Max arrays per bucket for the large array pool. |
Int32 | maxArraysPerBucketNormalPool | Max arrays per bucket for the normal array pool. |
Int32 | bufferCapacityInBytes | The length of the largest contiguous buffer that can be handled by this allocator instance. |
Properties
| Improve this Doc View SourceBufferCapacityInBytes
Gets the length of the largest contiguous buffer that can be handled by this allocator instance.
Declaration
public int BufferCapacityInBytes { get; }
Property Value
Type | Description |
---|---|
Int32 |
MaxPoolSizeInBytes
Gets the maximum size of pooled arrays in bytes.
Declaration
public int MaxPoolSizeInBytes { get; }
Property Value
Type | Description |
---|---|
Int32 |
PoolSelectorThresholdInBytes
Gets the threshold to pool arrays in SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.largeArrayPool which has less buckets for memory safety.
Declaration
public int PoolSelectorThresholdInBytes { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceAllocate<T>(Int32, AllocationOptions)
Allocates an IMemoryOwner<T>, holding a Memory<T> of length length
.
Declaration
public override IMemoryOwner<T> Allocate<T>(int length, AllocationOptions options = AllocationOptions.None)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | Size of the buffer to allocate. |
AllocationOptions | options | The allocation options. |
Returns
Type | Description |
---|---|
IMemoryOwner<T> | A buffer of values of type |
Type Parameters
Name | Description |
---|---|
T | Type of the data stored in the buffer. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | When length is zero or negative. |
InvalidMemoryOperationException | When length is over the capacity of the allocator. |
AllocateManagedByteBuffer(Int32, AllocationOptions)
Allocates an IManagedByteBuffer.
Declaration
public override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options = AllocationOptions.None)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The requested buffer length. |
AllocationOptions | options | The allocation options. |
Returns
Type | Description |
---|---|
IManagedByteBuffer | The IManagedByteBuffer. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | When length is zero or negative. |
InvalidMemoryOperationException | When length is over the capacity of the allocator. |
CreateDefault()
This is the default. Should be good for most use cases.
Declaration
public static ArrayPoolMemoryAllocator CreateDefault()
Returns
Type | Description |
---|---|
ArrayPoolMemoryAllocator | The memory manager. |
CreateWithAggressivePooling()
For environments where memory capabilities are not an issue, the maximum amount of array requests are pooled which results in optimal throughput.
Declaration
public static ArrayPoolMemoryAllocator CreateWithAggressivePooling()
Returns
Type | Description |
---|---|
ArrayPoolMemoryAllocator | The memory manager. |
CreateWithMinimalPooling()
For environments with very limited memory capabilities, only small buffers like image rows are pooled.
Declaration
public static ArrayPoolMemoryAllocator CreateWithMinimalPooling()
Returns
Type | Description |
---|---|
ArrayPoolMemoryAllocator | The memory manager. |
CreateWithModeratePooling()
For environments with limited memory capabilities, only small array requests are pooled, which can result in reduced throughput.
Declaration
public static ArrayPoolMemoryAllocator CreateWithModeratePooling()
Returns
Type | Description |
---|---|
ArrayPoolMemoryAllocator | The memory manager. |
GetBufferCapacityInBytes()
Gets the length of the largest contiguous buffer that can be handled by this allocator instance in bytes.
Declaration
protected override int GetBufferCapacityInBytes()
Returns
Type | Description |
---|---|
Int32 | The length of the largest contiguous buffer that can be handled by this allocator instance. |
Overrides
| Improve this Doc View SourceReleaseRetainedResources()
Releases all retained resources not being in use. Eg: by resetting array pools and letting GC to free the arrays.
Declaration
public override void ReleaseRetainedResources()