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

Constructors

MemoryAllocator()

protected MemoryAllocator()

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

Allocate<T>(int, AllocationOptions)

Allocates an IMemoryOwner<T>, holding a Memory<T> of length length.

public abstract 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

ArgumentOutOfRangeException

When length is zero or negative.

InvalidMemoryOperationException

When length is 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()