Class MemoryAllocator
- Namespace
- SixLabors.ImageSharp.Memory
- Assembly
- SixLabors.ImageSharp.dll
Memory managers are used to allocate memory for image processing operations.
public abstract class MemoryAllocator
- Inheritance
-
MemoryAllocator
- Derived
- Inherited Members
- Extension Methods
Properties
Default
Gets the default platform-specific global MemoryAllocator instance that serves as the default value for MemoryAllocator.
This is a get-only property, you should set Default's MemoryAllocator to change the default allocator used by Image and it's operations.
public static MemoryAllocator Default { get; }
Property Value
Methods
AllocateCore<T>(int, AllocationOptions)
Allocates a tracked memory owner for Allocate<T>(int, AllocationOptions).
protected abstract AllocationTrackedMemoryManager<T> AllocateCore<T>(int length, AllocationOptions options = AllocationOptions.None) where T : struct
Parameters
lengthintSize of the buffer to allocate.
optionsAllocationOptionsThe allocation options.
Returns
- AllocationTrackedMemoryManager<T>
A tracked memory owner of values of type
T.
Type Parameters
TType of the data stored in the buffer.
Remarks
Implementations should only allocate and initialize the concrete owner. The base allocator reserves bytes, attaches tracking to the returned owner, and releases the reservation if allocation fails.
Allocate<T>(int, AllocationOptions)
Allocates an IMemoryOwner<T>, holding a Memory<T> of length length.
public IMemoryOwner<T> Allocate<T>(int length, AllocationOptions options = AllocationOptions.None) where T : struct
Parameters
lengthintSize of the buffer to allocate.
optionsAllocationOptionsThe allocation options.
Returns
- IMemoryOwner<T>
A buffer of values of type
T.
Type Parameters
TType of the data stored in the buffer.
Exceptions
- InvalidMemoryOperationException
When length is negative or over the capacity of the allocator.
Create()
Creates a default instance of a MemoryAllocator optimized for the executing platform.
public static MemoryAllocator Create()
Returns
Create(MemoryAllocatorOptions)
Creates the default MemoryAllocator using the provided options.
public static MemoryAllocator Create(MemoryAllocatorOptions options)
Parameters
optionsMemoryAllocatorOptions
Returns
GetBufferCapacityInBytes()
Gets the length of the largest contiguous buffer that can be handled by this allocator instance in bytes.
protected abstract int GetBufferCapacityInBytes()
Returns
- int
The length of the largest contiguous buffer that can be handled by this allocator instance.
ReleaseRetainedResources()
Releases all retained resources not being in use. Eg: by resetting array pools and letting GC to free the arrays.
public virtual void ReleaseRetainedResources()
Remarks
This does not dispose active allocations; callers are responsible for disposing all IMemoryOwner<T> instances to release memory.