Struct UnsafePtrList
An unmanaged, resizable list, without any thread safety check features.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafePtrList
Constructors
UnsafePtrList(Int32, Allocator, NativeArrayOptions)
Constructs a new list using the specified type of memory allocation.
Declaration
public UnsafePtrList(int initialCapacity, Allocator allocator, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | initialCapacity | |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Remarks
The list initially has a capacity of one. To avoid reallocating memory for the list, specify sufficient capacity up front.
UnsafePtrList(Void**, Int32)
Constructs list as view into memory.
Declaration
public UnsafePtrList(void **ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
Void** | ptr | |
Int32 | length |
Fields
Allocator
Declaration
public readonly Allocator Allocator
Field Value
Type | Description |
---|---|
Allocator |
Capacity
Declaration
public readonly int Capacity
Field Value
Type | Description |
---|---|
Int32 |
Length
Declaration
public readonly int Length
Field Value
Type | Description |
---|---|
Int32 |
Ptr
Declaration
public readonly void **Ptr
Field Value
Type | Description |
---|---|
Void** |
Properties
IsCreated
Reports whether memory for the list is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this list object's internal storage has been allocated. |
Remarks
Note that the list storage is not created if you use the default constructor. You must specify at least an allocation type to construct a usable UnsafeList.
Methods
Add(Void*)
Adds an element to the list.
Declaration
public void Add(void *value)
Parameters
Type | Name | Description |
---|---|---|
Void* | value | The struct to be added at the end of the list. |
AddNoResize(Void*)
Adds an element to the list.
Declaration
public void AddNoResize(void *value)
Parameters
Type | Name | Description |
---|---|---|
Void* | value | The value to be added at the end of the list. |
Remarks
If the list has reached its current capacity, internal array won't be resized, and exception will be thrown.
AddRange(UnsafePtrList)
Adds the elements of a UnsafePtrList to this list.
Declaration
public void AddRange(UnsafePtrList list)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList | list | The items to add. |
AddRangeNoResize(Void**, Int32)
Adds elements from a buffer to this list.
Declaration
public void AddRangeNoResize(void **ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
Void** | ptr | A pointer to the buffer. |
Int32 | length | The number of elements to add to the list. |
Remarks
If the list has reached its current capacity, internal array won't be resized, and exception will be thrown.
AddRangeNoResize(UnsafePtrList)
Adds elements from a list to this list.
Declaration
public void AddRangeNoResize(UnsafePtrList list)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList | list |
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 UnsafePtrList.ParallelReader AsParallelReader()
Returns
Type | Description |
---|---|
UnsafePtrList.ParallelReader |
AsParallelWriter()
Returns parallel writer instance.
Declaration
public UnsafePtrList.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
UnsafePtrList.ParallelWriter |
Clear()
Clears the list.
Declaration
public void Clear()
Remarks
List Capacity remains unchanged.
Contains(Void*)
Determines whether an element is in the list.
Declaration
public bool Contains(void *value)
Parameters
Type | Name | Description |
---|---|---|
Void* | value |
Returns
Type | Description |
---|---|
Boolean | True, if element is found. |
Create(Int32, Allocator, NativeArrayOptions)
Creates a new list with the specified initial capacity and type of memory allocation.
Declaration
public static UnsafePtrList*Create(int initialCapacity, Allocator allocator, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
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 |
---|---|
UnsafePtrList* |
Create(Void**, Int32)
Declaration
public static UnsafePtrList*Create(void **ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
Void** | ptr | |
Int32 | length |
Returns
Type | Description |
---|---|
UnsafePtrList* |
Destroy(UnsafePtrList*)
Destroys list.
Declaration
public static void Destroy(UnsafePtrList*listData)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList* | 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(Void*)
Searches for the specified element in list.
Declaration
public int IndexOf(void *value)
Parameters
Type | Name | Description |
---|---|---|
Void* | value |
Returns
Type | Description |
---|---|
Int32 | The zero-based index of the first occurrence element if found, otherwise returns -1. |
RemoveAtSwapBack(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(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the item to delete. |
RemoveRangeSwapBack(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(int begin, int end)
Parameters
Type | Name | Description |
---|---|---|
Int32 | begin | The first index of the item to delete. |
Int32 | end | The last index of the item to delete. |
Resize(Int32, NativeArrayOptions)
Changes the list length, resizing if necessary.
Declaration
public void Resize(int length, NativeArrayOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The new length of the list. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
SetCapacity(Int32)
Set the number of items that can fit in the list.
Declaration
public void SetCapacity(int capacity)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The number of items that the list can hold before it resizes its internal storage. |
TrimExcess()
Sets the capacity to the actual number of elements in the container.
Declaration
public void TrimExcess()