Table of Contents

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

MemoryAllocator

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

length int

Size of the buffer to allocate.

options AllocationOptions

The allocation options.

Returns

AllocationTrackedMemoryManager<T>

A tracked memory owner of values of type T.

Type Parameters

T

Type 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

length int

Size of the buffer to allocate.

options AllocationOptions

The allocation options.

Returns

IMemoryOwner<T>

A buffer of values of type T.

Type Parameters

T

Type 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

MemoryAllocator

The MemoryAllocator.

Create(MemoryAllocatorOptions)

Creates the default MemoryAllocator using the provided options.

public static MemoryAllocator Create(MemoryAllocatorOptions options)

Parameters

options MemoryAllocatorOptions

The MemoryAllocatorOptions.

Returns

MemoryAllocator

The MemoryAllocator.

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.