# 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/6000.0/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.CoreModule
* **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

A NativeArray instance provides systems that means you can use them safely in jobs. A NativeArray also has automatic memory leak tracking.

## Constructors

| Constructor                                                                                                                                                                                                             | Description                                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| [NativeArray\`1(\`0\[\],Unity.Collections.Allocator)](/engine/6000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(0-allocator\))                                                                | Creates a NativeArray from an array of elements.                                              |
| [NativeArray\`1(System.Int32,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)](/engine/6000.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(Unity.Collections.NativeArray\{\`0},Unity.Collections.Allocator)](/engine/6000.0/script-reference/unity/collections/nativearray1/ctor.md#nativearray\(nativearrayt-allocator\))                         | Creates a NativeArray from an existing NativeArray.                                           |

## Properties

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

## Methods

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

## Static Methods

| Method                                                                         | Description                                                                                                                                      |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Copy](/engine/6000.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/6000.0/script-reference/unity/collections/nativearray1/readonly.md) | Represents a [NativeArray\<T>](/engine/6000.0/script-reference/unity/collections/nativearray1.md) interface constrained to read-only operations. |
