Struct UnsafeList
An unmanaged, untyped, resizable list, without any thread safety check features.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeList
Constructors
UnsafeList(Allocator)
Constructs a new list using the specified type of memory allocation.
Declaration
public UnsafeList(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Remarks
The list initially has a capacity of one. To avoid reallocating memory for the list, specify sufficient capacity up front.
UnsafeList(Int32, Int32, Int32, Allocator, NativeArrayOptions)
Constructs a new list with the specified initial capacity and type of memory allocation.
Declaration
public UnsafeList(int sizeOf, int alignOf, int initialCapacity, Allocator allocator, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sizeOf | Size of element. |
System.Int32 | alignOf | Alignment of element. |
System.Int32 | initialCapacity | The initial capacity of the list. If the list grows larger than its capacity, the internal array is copied to a new, larger array. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Fields
Allocator
Declaration
public Allocator Allocator
Field Value
Type | Description |
---|---|
Allocator |
Capacity
Declaration
public int Capacity
Field Value
Type | Description |
---|---|
System.Int32 |
Length
Declaration
public int Length
Field Value
Type | Description |
---|---|
System.Int32 |
Ptr
Declaration
public void *Ptr
Field Value
Type | Description |
---|---|
System.Void* |
Methods
Add<T>(T)
Adds an element to the list.
Declaration
public void Add<T>(T value)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be added at the end of the list. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Remarks
If the list has reached its current capacity, it copies the original, internal array to a new, larger array, and then deallocates the original.
AddNoResize<T>(T)
Adds an element to the list.
Declaration
public void AddNoResize<T>(T value)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be added at the end of the list. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Remarks
If the list has reached its current capacity, internal array won't be resized, and exception will be thrown.
AddRange<T>(Void*, Int32)
Adds elements from a buffer to this list.
Declaration
public void AddRange<T>(void *ptr, int length)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Void* | ptr | A pointer to the buffer. |
System.Int32 | length | The number of elements to add to the list. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
AddRange<T>(UnsafeList)
Adds elements from a list to this list.
Declaration
public void AddRange<T>(UnsafeList list)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
UnsafeList | list |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Remarks
If the list has reached its current capacity, it copies the original, internal array to a new, larger array, and then deallocates the original.
AddRangeNoResize<T>(Void*, Int32)
Adds elements from a buffer to this list.
Declaration
public void AddRangeNoResize<T>(void *ptr, int length)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Void* | ptr | A pointer to the buffer. |
System.Int32 | length | The number of elements to add to the list. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Remarks
If the list has reached its current capacity, internal array won't be resized, and exception will be thrown.
AddRangeNoResize<T>(UnsafeList)
Adds elements from a list to this list.
Declaration
public void AddRangeNoResize<T>(UnsafeList list)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
UnsafeList | list |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Remarks
If the list has reached its current capacity, internal array won't be resized, and exception will be thrown.
AsParallelReader()
Returns parallel reader instance.
Declaration
public UnsafeList.ParallelReader AsParallelReader()
Returns
Type | Description |
---|---|
UnsafeList.ParallelReader |
Clear()
Clears the list.
Declaration
public void Clear()
Remarks
List Capacity remains unchanged.
Contains<T>(T)
Determines whether an element is in the list.
Declaration
public bool Contains<T>(T value)
where T : struct, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
System.Boolean | True, if element is found. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Create(Int32, Int32, Int32, Allocator, NativeArrayOptions)
Creates a new list with the specified initial capacity and type of memory allocation.
Declaration
public static UnsafeList*Create(int sizeOf, int alignOf, int initialCapacity, Allocator allocator, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sizeOf | Size of element. |
System.Int32 | alignOf | Alignment of element. |
System.Int32 | initialCapacity | The initial capacity of the list. If the list grows larger than its capacity, the internal array is copied to a new, larger array. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Returns
Type | Description |
---|---|
UnsafeList* |
Destroy(UnsafeList*)
Destroys list.
Declaration
public static void Destroy(UnsafeList*listData)
Parameters
Type | Name | Description |
---|---|---|
UnsafeList* | listData |
Dispose()
Disposes of this container and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Remarks
You can call this function dispose of the container immediately after scheduling the job. Pass
the JobHandle returned by
the Job.Schedule
method using the jobHandle
parameter so the job scheduler can dispose the container after all jobs
using it have run.
IndexOf<T>(T)
Searches for the specified element in list.
Declaration
public int IndexOf<T>(T value)
where T : struct, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence element if found, otherwise returns -1. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
RemoveAtSwapBack<T>(Int32)
Truncates the list by replacing the item at the specified index with the last item in the list. The list is shortened by one.
Declaration
public void RemoveAtSwapBack<T>(int index)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the item to delete. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
RemoveRangeSwapBack<T>(Int32, Int32)
Truncates the list by replacing the item at the specified index range with the items from the end the list. The list is shortened by number of elements in range.
Declaration
public void RemoveRangeSwapBack<T>(int begin, int end)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | begin | The first index of the item to delete. |
System.Int32 | end | The last index of the item to delete. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
Resize(Int32, Int32, Int32, NativeArrayOptions)
Changes the list length, resizing if necessary.
Declaration
public void Resize(int sizeOf, int alignOf, int length, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sizeOf | Size of element. |
System.Int32 | alignOf | Alignment of element. |
System.Int32 | length | The new length of the list. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Resize<T>(Int32, NativeArrayOptions)
Changes the list length, resizing if necessary.
Declaration
public void Resize<T>(int length, NativeArrayOptions options = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The new length of the list. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |
SetCapacity<T>(Int32)
Set the number of items that can fit in the list.
Declaration
public void SetCapacity<T>(int capacity)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | The number of items that the list can hold before it resizes its internal storage. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements |