# NativeArray<T>

> Provides a buffer of native memory to managed code, making it possible to share data between managed and native code without marshalling costs.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections](/engine/7000.0/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [IEnumerable\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable), [IEquatable\<NativeArray\<T>>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct NativeArray<T> : IDisposable, IEnumerable<T>, IEnumerable, IEquatable<NativeArray<T>> where T : struct
```

## Remarks

NativeArray is a fixed-size block of unmanaged memory which you can directly access from managed code. You can use NativeArray instances in jobs and Burst-compiled code, with optional safety checks for bounds, access, and dependencies. You explicitly control allocation and disposal via an allocator, and Unity tracks allocations to help detect memory leaks.

## Constructors

| Constructor                                                                                                                                                                                                                 | Description                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| [NativeArray\`1(\`0\[\],Unity.Collections.Allocator)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(0-allocator\))                                                                    | Creates a NativeArray from an array of elements.                                                                                |
| [NativeArray\`1(\`0\[\],Unity.Collections.MemoryLabel)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(0-memorylabel\))                                                                | Creates a NativeArray from an array of elements, using the specified memory label.                                              |
| [NativeArray\`1(System.Int32,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(int-allocator-nativearrayoptions\))     | Creates a new NativeArray and allocates enough memory to fit the provided amount of elements.                                   |
| [NativeArray\`1(System.Int32,Unity.Collections.MemoryLabel,Unity.Collections.NativeArrayOptions)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(int-memorylabel-nativearrayoptions\)) | Creates a new NativeArray and allocates enough memory to fit the provided number of elements, using the specified memory label. |
| [NativeArray\`1(Unity.Collections.NativeArray\{\`0},Unity.Collections.Allocator)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(nativearrayt-allocator\))                             | Creates a NativeArray from an existing NativeArray.                                                                             |
| [NativeArray\`1(Unity.Collections.NativeArray\{\`0},Unity.Collections.MemoryLabel)](/engine/7000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(nativearrayt-memorylabel\))                         | Creates a NativeArray from an existing NativeArray, using the specified memory label.                                           |

## Properties

| Property                                                                                 | Description                                                                                                                           |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [IsCreated](/engine/7000.0/script-reference/unity/collections/nativearray1/iscreated.md) | Indicates that a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) has an allocated memory buffer. |
| [this\[\]](/engine/7000.0/script-reference/unity/collections/nativearray1/item.md)       | Access [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) elements by index.                        |
| [Length](/engine/7000.0/script-reference/unity/collections/nativearray1/length.md)       | Number of elements in a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md).                         |

## Methods

| Method                                                                                                 | Description                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AsReadOnly](/engine/7000.0/script-reference/unity/collections/nativearray1/asreadonly.md)             | Casts a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) to read-only array.                                               |
| [AsReadOnlySpan](/engine/7000.0/script-reference/unity/collections/nativearray1/asreadonlyspan.md)     | Exposes [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) data as a `System.ReadOnlySpan<T>`.                               |
| [AsSpan](/engine/7000.0/script-reference/unity/collections/nativearray1/asspan.md)                     | Exposes [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) data as a `System.Span<T>`.                                       |
| [CopyFrom](/engine/7000.0/script-reference/unity/collections/nativearray1/copyfrom.md)                 | Copies all the elements from a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) or a managed array of the same length.     |
| [CopyTo](/engine/7000.0/script-reference/unity/collections/nativearray1/copyto.md)                     | Copies all the elements to another [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) or a managed array of the same length. |
| [Dispose](/engine/7000.0/script-reference/unity/collections/nativearray1/dispose.md)                   | Disposes a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md).                                                               |
| [Equals](/engine/7000.0/script-reference/unity/collections/nativearray1/equals.md)                     | Compares a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) instance and an object.                                        |
| [GetEnumerator](/engine/7000.0/script-reference/unity/collections/nativearray1/getenumerator.md)       | Gets an enumerator.                                                                                                                                            |
| [GetHashCode](/engine/7000.0/script-reference/unity/collections/nativearray1/gethashcode.md)           | Gets a hash code for the current instance.                                                                                                                     |
| [GetSubArray](/engine/7000.0/script-reference/unity/collections/nativearray1/getsubarray.md)           | Gets a view into an array starting at the specified index.                                                                                                     |
| [Reinterpret](/engine/7000.0/script-reference/unity/collections/nativearray1/reinterpret.md)           | Reinterpret a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) with a different data type (type punning).                  |
| [ReinterpretLoad](/engine/7000.0/script-reference/unity/collections/nativearray1/reinterpretload.md)   | Reinterpret and load data starting at underlying index as a different type.                                                                                    |
| [ReinterpretStore](/engine/7000.0/script-reference/unity/collections/nativearray1/reinterpretstore.md) | Reinterpret and store data starting at underlying index as a different type.                                                                                   |
| [ToArray](/engine/7000.0/script-reference/unity/collections/nativearray1/toarray.md)                   | Convert a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) to an array.                                                    |

## Static Methods

| Method                                                                         | Description                                                                                                                                      |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Copy](/engine/7000.0/script-reference/unity/collections/nativearray1/copy.md) | Copies a range of elements from a source array to a destination array, starting from the source index and copying them to the destination index. |

## Structs

| Struct                                                                                                 | Description                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [NativeArray\<T>.ReadOnly](/engine/7000.0/script-reference/unity/collections/nativearray1/readonly.md) | Represents a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) interface constrained to read-only operations. |
