# Allocate

> Allocates memory directly from an allocator.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

## Allocate\<T>(T, int, int, int)

Allocates memory directly from an allocator.

```csharp
public static void* Allocate<T>(this ref T t, int sizeOf, int alignOf, int items = 1) where T : unmanaged, AllocatorManager.IAllocator
```

### Parameters

**** (T): The allocator of type T used to allocator memory.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to allocate to item.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The alignment in bytes.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of items. Defaults to 1.

### Returns

| Type                                                         | Description                        |
| ------------------------------------------------------------ | ---------------------------------- |
| [void\*](https://learn.microsoft.com/dotnet/api/system.void) | A pointer to the allocated memory. |

## Allocate(AllocatorHandle, int, int, int)

Allocates memory from an allocator.

```csharp
public static void* Allocate(AllocatorManager.AllocatorHandle handle, int itemSizeInBytes, int alignmentInBytes, int items = 1)
```

### Parameters

**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): A handle to the allocator.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to allocate.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The alignment in bytes (must be a power of two).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of values to allocate space for. Defaults to 1.

### Returns

| Type                                                         | Description                        |
| ------------------------------------------------------------ | ---------------------------------- |
| [void\*](https://learn.microsoft.com/dotnet/api/system.void) | A pointer to the allocated memory. |

## Allocate\<T>(AllocatorHandle, int)

Allocates enough memory for an unmanaged value of a given type.

```csharp
public static T* Allocate<T>(AllocatorManager.AllocatorHandle handle, int items = 1) where T : unmanaged
```

### Parameters

**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): A handle to the allocator.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of values to allocate for space for. Defaults to 1.

### Returns

| Type            | Description                        |
| --------------- | ---------------------------------- |
| [\<T>\*](./.md) | A pointer to the allocated memory. |
