The collections provided by this package fall into three categories:
- The collection types in
Unity.Collections
whose names start withNative-
have safety checks for ensuring that they're properly disposed and are used in a thread-safe manner. - The collection types in
Unity.Collections.LowLevel.Unsafe
whose names start withUnsafe-
do not have these safety checks. - The remaining collection types are not allocated and contain no pointers, so effectively their disposal and thread safety are never a concern. These types hold only small amounts of data.
Allocator.Temp
: The fastest allocator. For very short-lived allocations. Temp allocations cannot be passed into jobs.Allocator.TempJob
: The next fastest allocator. For short-lived allocations (4-frame lifetime). TempJob allocations can be passed into jobs.Allocator.Persistent
: The slowest allocator. For indefinite lifetime allocations. Persistent allocations can be passed into jobs.
A few key array-like types are provided by the core module, including Unity.Collections.NativeArray<T>
and Unity.Collections.NativeSlice<T>
. This package itself provides:
NativeList | A resizable list. |
UnsafeList | A resizable list. |
UnsafePtrList | A resizable list of pointers. |
NativeStream | A set of append-only, untyped buffers. |
UnsafeStream | A set of append-only, untyped buffers. |
UnsafeAppendBuffer | An append-only untyped buffer. |
NativeQueue | A resizable queue. |
UnsafeRingQueue | A fixed-size circular buffer. |
FixedList32Bytes | A 32-byte list, including 2 bytes of overhead, so 30 bytes are available for storage. Max capacity depends upon the type parameter. |
FixedList64Bytes | A 64-byte list, including 2 bytes of overhead, so 62 bytes are available for storage. Max capacity depends upon the type parameter. |
FixedList128Bytes | A 128-byte list, including 2 bytes of overhead, so 126 bytes are available for storage. Max capacity depends upon the type parameter. |
FixedList512Bytes | A 512-byte list, including 2 bytes of overhead, so 510 bytes are available for storage. Max capacity depends upon the type parameter. |
FixedList4096Bytes | A 4096-byte list, including 2 bytes of overhead, so 4094 bytes are available for storage. Max capacity depends upon the type parameter. |
There are no multi-dimensional array types, but you can simply pack multi-dimensional data into a single-dimension: for example, for an int[4][5]
array, use an int[20]
array instead (because 4 * 5
is 20
).
When using the Entities package, a DynamicBuffer component is often the best choice for an array- or list-like collection.
See also NativeArrayExtensions, ListExtensions, NativeSortExtension.
NativeParallelHashMap | An unordered associative array of key-value pairs. |
UnsafeParallelHashMap | An unordered associative array of key-value pairs. |
NativeParallelHashSet | A set of unique values. |
UnsafeParallelHashSet | A set of unique values. |
NativeMultiHashMap | An unordered associative array of key-value pairs. The keys do not have to be unique, i.e. two pairs can have equal keys. |
UnsafeMultiHashMap | An unordered associative array of key-value pairs. The keys do not have to be unique, i.e. two pairs can have equal keys. |
See also HashSetExtensions, Unity.Collections.NotBurstCompatible.Extensions, and Unity.Collections.LowLevel.Unsafe.NotBurstCompatible.Extensions
BitField32 | A fixed-size array of 32 bits. |
BitField64 | A fixed-size array of 64 bits. |
NativeBitArray | An arbitrary-sized array of bits. |
UnsafeBitArray | An arbitrary-sized array of bits. |
NativeText | A UTF-8 encoded string. Mutable and resizable. |
FixedString32Bytes | A 32-byte UTF-8 encoded string, including 3 bytes of overhead, so 29 bytes available for storage. |
FixedString64Bytes | A 64-byte UTF-8 encoded string, including 3 bytes of overhead, so 61 bytes available for storage. |
FixedString128Bytes | A 128-byte UTF-8 encoded string, including 3 bytes of overhead, so 125 bytes available for storage. |
FixedString512Bytes | A 512-byte UTF-8 encoded string, including 3 bytes of overhead, so 509 bytes available for storage. |
FixedString4096Bytes | A 4096-byte UTF-8 encoded string, including 3 bytes of overhead, so 4093 bytes available for storage. |
See also FixedString and FixedStringMethods.
NativeReference | A reference to a single value. Functionally equivalent to an array of length 1. |
UnsafeAtomicCounter32 | A 32-bit atomic counter. |
UnsafeAtomicCounter64 | A 64-bit atomic counter. |
Most of the collections have a GetEnumerator
method, which returns an implementation of IEnumerator<T>
. The enumerator's MoveNext
method advances its Current
property to the next element.
Several of the collection types have nested types for reading and writing from parallel jobs. For example, to write safely to a NativeList<T>
from a parallel job, you need a NativeList<T>.ParallelWriter
.