# CreateNativeArray

> Create a NativeArray, using a provided allocator that implements IAllocator.

## Definition

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

## CreateNativeArray\<T, U>(int, T, NativeArrayOptions)

Create a NativeArray, using a provided allocator that implements IAllocator.

```csharp
public static NativeArray<T> CreateNativeArray<T, U>(int length, ref U allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : unmanaged where U : unmanaged, AllocatorManager.IAllocator
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to allocate.**** (T): The allocator to use.**** (\[NativeArrayOptions]\(/engine/6000.7/script-reference/unity/collections/nativearrayoptions)): Options for allocation, such as whether to clear the memory.

### Returns

| Type                                                                                 | Description                               |
| ------------------------------------------------------------------------------------ | ----------------------------------------- |
| [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) | Returns the NativeArray that was created. |

## CreateNativeArray\<T>(int, AllocatorHandle, NativeArrayOptions)

Create a NativeArray, using a provided AllocatorHandle.

```csharp
public static NativeArray<T> CreateNativeArray<T>(int length, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : unmanaged
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to allocate.**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): The AllocatorHandle to use.**** (\[NativeArrayOptions]\(/engine/6000.7/script-reference/unity/collections/nativearrayoptions)): Options for allocation, such as whether to clear the memory.

### Returns

| Type                                                                                 | Description                               |
| ------------------------------------------------------------------------------------ | ----------------------------------------- |
| [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) | Returns the NativeArray that was created. |

## CreateNativeArray\<T>(NativeArray\<T>, AllocatorHandle)

Create a NativeArray from another NativeArray, using a provided AllocatorHandle.

```csharp
public static NativeArray<T> CreateNativeArray<T>(NativeArray<T> array, AllocatorManager.AllocatorHandle allocator) where T : unmanaged
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The NativeArray to make a copy of.**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): The AllocatorHandle to use.

### Returns

| Type                                                                                 | Description                               |
| ------------------------------------------------------------------------------------ | ----------------------------------------- |
| [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) | Returns the NativeArray that was created. |

## CreateNativeArray\<T>(\`\<>\[], AllocatorHandle)

Create a NativeArray from a managed array, using a provided AllocatorHandle.

```csharp
[ExcludeFromBurstCompatTesting("Managed array")]
public static NativeArray<T> CreateNativeArray<T>(T[] array, AllocatorManager.AllocatorHandle allocator) where T : unmanaged
```

### Parameters

**** (\[\<T>\[]]\(./)): The managed array to make a copy of.**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): The AllocatorHandle to use.

### Returns

| Type                                                                                 | Description                               |
| ------------------------------------------------------------------------------------ | ----------------------------------------- |
| [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) | Returns the NativeArray that was created. |

## CreateNativeArray\<T, U>(\`\<>\[], T)

Create a NativeArray from a managed array, using a provided Allocator.

```csharp
[ExcludeFromBurstCompatTesting("Managed array")]
public static NativeArray<T> CreateNativeArray<T, U>(T[] array, ref U allocator) where T : unmanaged where U : unmanaged, AllocatorManager.IAllocator
```

### Parameters

**** (\[\<T>\[]]\(./)): The managed array to make a copy of.**** (T): The Allocator to use.

### Returns

| Type                                                                                 | Description                               |
| ------------------------------------------------------------------------------------ | ----------------------------------------- |
| [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) | Returns the NativeArray that was created. |
