Class AllocatorManager
Manages custom memory allocators.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
public static class AllocatorManagerFields
FirstUserIndex
Index in the global function table of the first user-defined allocator.
Declaration
public const ushort FirstUserIndex = 64Field Value
| Type | Description | 
|---|---|
| ushort | Index in the global function table of the first user-defined allocator. | 
Remarks
The indexes from 0 up to FirstUserIndex are reserved and so should not be used for your own allocators.
Invalid
Corresponds to Allocator.Invalid.
Declaration
public static readonly AllocatorManager.AllocatorHandle InvalidField Value
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | Corresponds to Allocator.Invalid. | 
MaxNumCustomAllocators
Maximum number of user-defined allocators.
Declaration
public const ushort MaxNumCustomAllocators = 32768Field Value
| Type | Description | 
|---|---|
| ushort | 
None
Corresponds to Allocator.None.
Declaration
public static readonly AllocatorManager.AllocatorHandle NoneField Value
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | Corresponds to Allocator.None. | 
Persistent
Corresponds to Allocator.Persistent.
Declaration
public static readonly AllocatorManager.AllocatorHandle PersistentField Value
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | Corresponds to Allocator.Persistent. | 
Temp
Corresponds to Allocator.Temp.
Declaration
public static readonly AllocatorManager.AllocatorHandle TempField Value
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | Corresponds to Allocator.Temp. | 
TempJob
Corresponds to Allocator.TempJob.
Declaration
public static readonly AllocatorManager.AllocatorHandle TempJobField Value
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | Corresponds to Allocator.TempJob. | 
kErrorBufferOverflow
Memory allocation Buffer Overflow status
Declaration
public const int kErrorBufferOverflow = -1Field Value
| Type | Description | 
|---|---|
| int | 
kErrorNone
Memory allocation Success status
Declaration
public const int kErrorNone = 0Field Value
| Type | Description | 
|---|---|
| int | 
Methods
Allocate(AllocatorHandle, int, int, int)
Allocates memory from an allocator.
Declaration
public static void* Allocate(AllocatorManager.AllocatorHandle handle, int itemSizeInBytes, int alignmentInBytes, int items = 1)Parameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.AllocatorHandle | handle | A handle to the allocator. | 
| int | itemSizeInBytes | The number of bytes to allocate. | 
| int | alignmentInBytes | The alignment in bytes (must be a power of two). | 
| int | items | The number of values to allocate space for. Defaults to 1. | 
Returns
| Type | Description | 
|---|---|
| void* | A pointer to the allocated memory. | 
Allocate<T>(AllocatorHandle, int)
Allocates enough memory for an unmanaged value of a given type.
Declaration
public static T* Allocate<T>(AllocatorManager.AllocatorHandle handle, int items = 1) where T : unmanagedParameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.AllocatorHandle | handle | A handle to the allocator. | 
| int | items | The number of values to allocate for space for. Defaults to 1. | 
Returns
| Type | Description | 
|---|---|
| T* | A pointer to the allocated memory. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of value to allocate for. | 
Allocate<T>(ref T, int, int, int)
Allocates memory directly from an allocator.
Declaration
public static void* Allocate<T>(this ref T t, int sizeOf, int alignOf, int items = 1) where T : unmanaged, AllocatorManager.IAllocatorParameters
| Type | Name | Description | 
|---|---|---|
| T | t | The allocator of type T used to allocator memory. | 
| int | sizeOf | The number of bytes to allocate to item. | 
| int | alignOf | The alignment in bytes. | 
| int | items | The number of items. Defaults to 1. | 
Returns
| Type | Description | 
|---|---|
| void* | A pointer to the allocated memory. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of allocator. | 
ConvertToAllocatorHandle(Allocator)
Convert an Allocator to an AllocatorHandle, keeping the Version.
Declaration
public static AllocatorManager.AllocatorHandle ConvertToAllocatorHandle(Allocator a)Parameters
| Type | Name | Description | 
|---|---|---|
| Allocator | a | The Allocator to convert. | 
Returns
| Type | Description | 
|---|---|
| AllocatorManager.AllocatorHandle | The AllocatorHandle of an allocator. | 
Free(AllocatorHandle, void*)
Frees an allocation.
Declaration
public static void Free(AllocatorManager.AllocatorHandle handle, void* pointer)Parameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.AllocatorHandle | handle | A handle to the allocator. | 
| void* | pointer | A pointer to the allocated memory. | 
Free(AllocatorHandle, void*, int, int, int)
Frees an allocation.
Declaration
public static void Free(AllocatorManager.AllocatorHandle handle, void* pointer, int itemSizeInBytes, int alignmentInBytes, int items = 1)Parameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.AllocatorHandle | handle | A handle to the allocator. | 
| void* | pointer | A pointer to the allocated memory. | 
| int | itemSizeInBytes | The size in bytes of the allocation. | 
| int | alignmentInBytes | The alignment in bytes (must be a power of two). | 
| int | items | The number of values that the memory was allocated for. | 
Remarks
For some allocators, the size of the allocation must be known to properly deallocate.
Other allocators only need the pointer when deallocating and so will ignore itemSizeInBytes, alignmentInBytes and items.
Free<T>(AllocatorHandle, T*, int)
Frees an allocation.
Declaration
public static void Free<T>(AllocatorManager.AllocatorHandle handle, T* pointer, int items = 1) where T : unmanagedParameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.AllocatorHandle | handle | A handle to the allocator. | 
| T* | pointer | A pointer to the allocated memory. | 
| int | items | The number of values that the memory was allocated for. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of value that the memory was allocated for. | 
Remarks
For some allocators, the size of the allocation must be known to properly deallocate.
Other allocators only need the pointer when deallocating and so  will ignore T and items.
Register<T>(ref T, bool, bool, int)
Saves an allocator's function pointers in a free slot of the global function table. Thread safe.
Declaration
[ExcludeFromBurstCompatTesting("Uses managed delegate")]
public static void Register<T>(this ref T t, bool IsAutoDispose = false, bool isGlobal = false, int globalIndex = 0) where T : unmanaged, AllocatorManager.IAllocatorParameters
| Type | Name | Description | 
|---|---|---|
| T | t | Reference to the allocator. | 
| bool | IsAutoDispose | Flag indicating if the allocator will automatically dispose allocations. | 
| bool | isGlobal | Flag indicating if the allocator is a global allocator. | 
| int | globalIndex | Index into the global function table of the allocator to be created. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of allocator to register. | 
Try(ref Block)
Invokes the allocator function of a block.
Declaration
public static int Try(ref AllocatorManager.Block block)Parameters
| Type | Name | Description | 
|---|---|---|
| AllocatorManager.Block | block | The block to allocate, deallocate, or reallocate. | 
Returns
| Type | Description | 
|---|---|
| int | 0 if successful. Otherwise, returns the error code from the block's allocator function. | 
Remarks
The allocator function is looked up from a global table.
 - If the block range's Pointer is null, it will allocate.
 - If the block range's Pointer is not null, it will reallocate.
 - If the block range's Items is 0, it will deallocate.
UnmanagedUnregister<T>(ref T)
Removes an allocator's function pointers from the global function table, without managed code
Declaration
public static void UnmanagedUnregister<T>(this ref T t) where T : unmanaged, AllocatorManager.IAllocatorParameters
| Type | Name | Description | 
|---|---|---|
| T | t | Reference to the allocator. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of allocator to unregister. | 
Unregister<T>(ref T)
Removes an allocator's function pointers from the global function table.
Declaration
[ExcludeFromBurstCompatTesting("Uses managed delegate")]
public static void Unregister<T>(this ref T t) where T : unmanaged, AllocatorManager.IAllocatorParameters
| Type | Name | Description | 
|---|---|---|
| T | t | Reference to the allocator. | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type of allocator to unregister. |