Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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.
Read time 2 minutesLast updated 6 days ago

Definition

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)Creates a NativeArray from an array of elements.
NativeArray`1(System.Int32,Unity.Collections.Allocator,Unity.Collections.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)Creates a NativeArray from an existing NativeArray.

Properties

Property

Description

IsCreatedIndicates that a NativeArray<T> has an allocated memory buffer.
this[]Access NativeArray<T> elements by index.
LengthNumber of elements in a NativeArray<T>.

Methods

Method

Description

AsReadOnlyCasts a NativeArray<T> to read-only array.
AsReadOnlySpanExposes NativeArray<T> data as a
System.ReadOnlySpan<T>
.
AsSpanExposes NativeArray<T> data as a
System.Span<T>
.
CopyFromCopies all the elements from a NativeArray<T> or a managed array of the same length.
CopyToCopies all the elements to another NativeArray<T> or a managed array of the same length.
DisposeDisposes a NativeArray<T>.
EqualsCompares a NativeArray<T> instance and an object.
GetEnumeratorGets an enumerator.
GetHashCodeGets a hash code for the current instance.
GetSubArrayGets a view into an array starting at the specified index.
ReinterpretReinterpret a NativeArray<T> with a different data type (type punning).
ReinterpretLoadReinterpret and load data starting at underlying index as a different type.
ReinterpretStoreReinterpret and store data starting at underlying index as a different type.
ToArrayConvert a NativeArray<T> to an array.

Static Methods

Method

Description

CopyCopies 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>.ReadOnlyRepresents a NativeArray<T> interface constrained to read-only operations.