Struct UnsafePtrList<T>
An unmanaged, resizable list of pointers.
Implements
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public struct UnsafePtrList<T> : INativeDisposable where T : unmanaged
Type Parameters
Name | Description |
---|---|
T | The type of pointer element. |
Constructors
UnsafePtrList(int, AllocatorHandle, NativeArrayOptions)
Initializes and returns an instance of UnsafePtrList.
Declaration
public UnsafePtrList(int initialCapacity, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.UninitializedMemory)
Parameters
Type | Name | Description |
---|---|---|
int | initialCapacity | The initial capacity of the list. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
UnsafePtrList(T**, int)
Initializes and returns an instance of UnsafePtrList.
Declaration
public UnsafePtrList(T** ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
T** | ptr | An existing pointer array to set as the internal buffer. |
int | length | The length. |
Fields
Allocator
The allocator used to create the internal buffer.
Declaration
public readonly AllocatorManager.AllocatorHandle Allocator
Field Value
Type | Description |
---|---|
AllocatorManager.AllocatorHandle |
Ptr
The internal buffer of this list.
Declaration
[NativeDisableUnsafePtrRestriction]
public readonly T** Ptr
Field Value
Type | Description |
---|---|
T** |
capacity
The number of elements that can fit in the internal buffer.
Declaration
public readonly int capacity
Field Value
Type | Description |
---|---|
int |
length
The number of elements.
Declaration
public readonly int length
Field Value
Type | Description |
---|---|
int |
unused
Declaration
public int unused
Field Value
Type | Description |
---|---|
int |
Properties
Capacity
The number of elements that can fit in the internal buffer.
Declaration
public int Capacity { get; set; }
Property Value
Type | Description |
---|---|
int | The number of elements that can fit in the internal buffer. |
IsCreated
Whether this list has been allocated (and not yet deallocated).
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool | True if this list has been allocated (and not yet deallocated). |
IsEmpty
Whether the list is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool | True if the list is empty. |
this[int]
The element at an index.
Declaration
public T* this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | An index. |
Property Value
Type | Description |
---|---|
T* | The element at the index. |
Length
The number of elements.
Declaration
public int Length { get; set; }
Property Value
Type | Description |
---|---|
int | The number of elements. |
Methods
Add(in IntPtr)
Adds a pointer to the end of the list.
Declaration
public void Add(in IntPtr value)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | value | The pointer to add to the end of this list. |
Remarks
Increments the length by 1. Increases the capacity if necessary.
Add(void*)
Adds a pointer to the end of the list.
Declaration
public void Add(void* value)
Parameters
Type | Name | Description |
---|---|---|
void* | value | The pointer to add to the end of this list. |
Remarks
Increments the length by 1. Increases the capacity if necessary.
AddNoResize(void*)
Adds a pointer to the end of this list.
Declaration
public void AddNoResize(void* value)
Parameters
Type | Name | Description |
---|---|---|
void* | value | The pointer to add to the end of the list. |
Remarks
Increments the length by 1. Never increases the capacity.
Exceptions
Type | Condition |
---|---|
Exception | Thrown if incrementing the length would exceed the capacity. |
AddRange(void*, int)
Adds elements from a buffer to this list.
Declaration
public void AddRange(void* ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | A pointer to the buffer. |
int | length | The number of elements to add to the list. |
AddRange(UnsafePtrList<T>)
Copies the elements of another list to the end of this list.
Declaration
public void AddRange(UnsafePtrList<T> list)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList<T> | list | The other list to copy from. |
Remarks
Increments the length by the length of the other list. Increases the capacity if necessary.
AddRangeNoResize(void**, int)
Copies pointers from a buffer to the end of this list.
Declaration
public void AddRangeNoResize(void** ptr, int count)
Parameters
Type | Name | Description |
---|---|---|
void** | ptr | The buffer to copy from. |
int | count | The number of pointers to copy from the buffer. |
Remarks
Increments the length by count
. Never increases the capacity.
Exceptions
Type | Condition |
---|---|
Exception | Thrown if the increased length would exceed the capacity. |
AddRangeNoResize(UnsafePtrList<T>)
Copies the pointers of another list to the end of this list.
Declaration
public void AddRangeNoResize(UnsafePtrList<T> list)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList<T> | list | The other list to copy from. |
Remarks
Increments the length by the length of the other list. Never increases the capacity.
Exceptions
Type | Condition |
---|---|
Exception | Thrown if the increased length would exceed the capacity. |
AsParallelReader()
Returns a parallel reader of this list.
Declaration
public UnsafePtrList<T>.ParallelReader AsParallelReader()
Returns
Type | Description |
---|---|
UnsafePtrList<T>.ParallelReader | A parallel reader of this list. |
AsParallelWriter()
Returns a parallel writer of this list.
Declaration
public UnsafePtrList<T>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
UnsafePtrList<T>.ParallelWriter | A parallel writer of this list. |
Clear()
Sets the length to 0.
Declaration
public void Clear()
Remarks
Does not change the capacity.
Contains(void*)
Returns true if the list contains at least one occurrence of a specific pointer.
Declaration
public bool Contains(void* ptr)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | The pointer to search for in the list. |
Returns
Type | Description |
---|---|
bool | True if the list contains at least one occurrence of the pointer. |
Create(int, AllocatorHandle, NativeArrayOptions)
Returns a new list of pointers.
Declaration
public static UnsafePtrList<T>* Create(int initialCapacity, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.UninitializedMemory)
Parameters
Type | Name | Description |
---|---|---|
int | initialCapacity | The initial capacity of the list. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
Returns
Type | Description |
---|---|
UnsafePtrList<T>* | A pointer to the new list. |
Create(T**, int)
Returns a new list of pointers.
Declaration
public static UnsafePtrList<T>* Create(T** ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
T** | ptr | An existing pointer array to set as the internal buffer. |
int | length | The length. |
Returns
Type | Description |
---|---|
UnsafePtrList<T>* | A pointer to the new list. |
Destroy(UnsafePtrList<T>*)
Destroys the list.
Declaration
public static void Destroy(UnsafePtrList<T>* listData)
Parameters
Type | Name | Description |
---|---|---|
UnsafePtrList<T>* | listData | The list to destroy. |
Dispose()
Releases all resources (memory).
Declaration
public void Dispose()
Dispose(JobHandle)
Creates and schedules a job that frees the memory of this list.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The dependency for the new job. |
Returns
Type | Description |
---|---|
JobHandle | The handle of the new job. The job depends upon |
ElementAt(int)
Returns a reference to the element at a given index.
Declaration
public ref T* ElementAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to access. Must be in the range of [0..Length). |
Returns
Type | Description |
---|---|
T* | A reference to the element at the index. |
IndexOf(void*)
Returns the index of the first occurrence of a specific pointer in the list.
Declaration
public int IndexOf(void* ptr)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | The pointer to search for in the list. |
Returns
Type | Description |
---|---|
int | The index of the first occurrence of the pointer. Returns -1 if it is not found in the list. |
InsertRangeWithBeginEnd(int, int)
Shifts pointers toward the end of this list, increasing its length.
Declaration
public void InsertRangeWithBeginEnd(int begin, int end)
Parameters
Type | Name | Description |
---|---|---|
int | begin | The index of the first pointer that will be shifted up. |
int | end | The index where the first shifted pointer will end up. |
Remarks
Right-shifts pointers in the list so as to create 'free' slots at the beginning or in the middle.
The length is increased by end - begin
. If necessary, the capacity will be increased accordingly.
If end
equals begin
, the method does nothing.
The pointer at index begin
will be copied to index end
, the pointer at index begin + 1
will be copied to end + 1
, and so forth.
The indexes begin
up to end
are not cleared: they will contain whatever pointers they held prior.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
ArgumentOutOfRangeException | Thrown if |
RemoveAt(int)
Removes the pointer at an index, shifting everything above it down by one. Decrements the length by 1.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the pointer to remove. |
Remarks
If you don't care about preserving the order of the pointers, RemoveAtSwapBack(int) is a more efficient way to remove pointers.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
RemoveAtSwapBack(int)
Copies the last pointer of this list to the specified index. Decrements the length by 1.
Declaration
public void RemoveAtSwapBack(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to overwrite with the last pointer. |
Remarks
Useful as a cheap way to remove a pointer from this list when you don't care about preserving order.
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | Thrown if |
RemoveRange(int, int)
Removes N pointers in a range, shifting everything above the range down by N. Decrements the length by N.
Declaration
public void RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the first pointer to remove. |
int | count | The number of pointers to remove. |
Remarks
If you don't care about preserving the order of the pointers, RemoveRangeSwapBackWithBeginEnd(int, int) is a more efficient way to remove pointers.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
RemoveRangeSwapBack(int, int)
Copies the last N pointer of this list to a range in this list. Decrements the length by N.
Declaration
public void RemoveRangeSwapBack(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the first pointer to overwrite. |
int | count | The number of pointers to copy and remove. |
Remarks
Copies the last count
pointers to the indexes index
up to index + count
.
Useful as a cheap way to remove pointers from a list when you don't care about preserving order.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
Resize(int, NativeArrayOptions)
Sets the length, expanding the capacity if necessary.
Declaration
public void Resize(int length, NativeArrayOptions options = NativeArrayOptions.UninitializedMemory)
Parameters
Type | Name | Description |
---|---|---|
int | length | The new length. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
SetCapacity(int)
Sets the capacity.
Declaration
public void SetCapacity(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | The new capacity. |
TrimExcess()
Sets the capacity to match the length.
Declaration
public void TrimExcess()