Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CreateNativeArray

Create a NativeArray, using a provided allocator that implements IAllocator.
Read time 2 minutesLast updated 7 days ago

Definition

  • Type: Method
  • Namespace: Unity.Collections
  • Assembly: UnityEngine.ManagedKernelModule

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

Create a NativeArray, using a provided allocator that implements IAllocator.
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

length

The number of elements to allocate.

allocator

T
The allocator to use.

Options for allocation, such as whether to clear the memory.

Returns

Type

Description

NativeArray<T>Returns the NativeArray that was created.

CreateNativeArray<T>(int, AllocatorHandle, NativeArrayOptions)

Create a NativeArray, using a provided AllocatorHandle.
public static NativeArray<T> CreateNativeArray<T>(int length, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : unmanaged

Parameters

length

The number of elements to allocate.

The AllocatorHandle to use.

Options for allocation, such as whether to clear the memory.

Returns

Type

Description

NativeArray<T>Returns the NativeArray that was created.

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

Create a NativeArray from another NativeArray, using a provided AllocatorHandle.
public static NativeArray<T> CreateNativeArray<T>(NativeArray<T> array, AllocatorManager.AllocatorHandle allocator) where T : unmanaged

Parameters

The NativeArray to make a copy of.

The AllocatorHandle to use.

Returns

Type

Description

NativeArray<T>Returns the NativeArray that was created.

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

Create a NativeArray from a managed array, using a provided AllocatorHandle.
[ExcludeFromBurstCompatTesting("Managed array")]public static NativeArray<T> CreateNativeArray<T>(T[] array, AllocatorManager.AllocatorHandle allocator) where T : unmanaged

Parameters

array

The managed array to make a copy of.

The AllocatorHandle to use.

Returns

Type

Description

NativeArray<T>Returns the NativeArray that was created.

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

Create a NativeArray from a managed array, using a provided Allocator.
[ExcludeFromBurstCompatTesting("Managed array")]public static NativeArray<T> CreateNativeArray<T, U>(T[] array, ref U allocator) where T : unmanaged where U : unmanaged, AllocatorManager.IAllocator

Parameters

array

The managed array to make a copy of.

allocator

T
The Allocator to use.

Returns

Type

Description

NativeArray<T>Returns the NativeArray that was created.