Struct UnsafePtrList<T>
An unmanaged, resizable list of pointers.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafePtrList<T> : INativeDisposable, IDisposable, IEnumerable<IntPtr>, IEnumerable where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of pointer element. |
Constructors
UnsafePtrList(T**, Int32)
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. |
Int32 | length | The length. |
UnsafePtrList(Int32, AllocatorManager.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 |
---|---|---|
Int32 | initialCapacity | The initial capacity of the list. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
Fields
Allocator
The allocator used to create the internal buffer.
Declaration
public readonly AllocatorManager.AllocatorHandle Allocator
Field Value
Type | Description |
---|---|
AllocatorManager.AllocatorHandle |
m_capacity
The number of elements that can fit in the internal buffer.
Declaration
public readonly int m_capacity
Field Value
Type | Description |
---|---|
Int32 |
m_length
The number of elements.
Declaration
public readonly int m_length
Field Value
Type | Description |
---|---|
Int32 |
Ptr
The internal buffer of this list.
Declaration
[NativeDisableUnsafePtrRestriction]
public readonly T**Ptr
Field Value
Type | Description |
---|---|
T** |
Properties
Capacity
The number of elements that can fit in the internal buffer.
Declaration
public int Capacity { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of elements that can fit in the internal buffer. |
IsCreated
Whether this list has been allocated (and not yet deallocated).
Declaration
public readonly bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this list has been allocated (and not yet deallocated). |
IsEmpty
Whether the list is empty.
Declaration
public readonly bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean | True if the list is empty or the list has not been constructed. |
Item[Int32]
The element at an index.
Declaration
public T*this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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 |
---|---|
Int32 | 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*, Int32)
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. |
Int32 | 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**, Int32)
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. |
Int32 | 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.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.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 |
---|---|
Boolean | True if the list contains at least one occurrence of the pointer. |
Create(T**, Int32)
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. |
Int32 | length | The length. |
Returns
Type | Description |
---|---|
UnsafePtrList<T>* | A pointer to the new list. |
Create(Int32, AllocatorManager.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 |
---|---|---|
Int32 | 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. |
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 |
Implements
ElementAt(Int32)
Returns a reference to the element at a given index.
Declaration
public ref T*ElementAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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 |
---|---|
Int32 | The index of the first occurrence of the pointer. Returns -1 if it is not found in the list. |
InsertRangeWithBeginEnd(Int32, Int32)
Shifts pointers toward the end of this list, increasing its length.
Declaration
public void InsertRangeWithBeginEnd(int begin, int end)
Parameters
Type | Name | Description |
---|---|---|
Int32 | begin | The index of the first pointer that will be shifted up. |
Int32 | 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(Int32)
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 |
---|---|---|
Int32 | index | The index of the pointer to remove. |
Remarks
If you don't care about preserving the order of the pointers, RemoveAtSwapBack(Int32) is a more efficient way to remove pointers.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
RemoveAtSwapBack(Int32)
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 |
---|---|---|
Int32 | 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(Int32, Int32)
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 |
---|---|---|
Int32 | index | The index of the first pointer to remove. |
Int32 | count | The number of pointers to remove. |
Remarks
If you don't care about preserving the order of the pointers, Unity.Collections.LowLevel.Unsafe.UnsafePtrList`1.RemoveRangeSwapBackWithBeginEnd(System.Int32,System.Int32) is a more efficient way to remove pointers.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
RemoveRangeSwapBack(Int32, Int32)
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 |
---|---|---|
Int32 | index | The index of the first pointer to overwrite. |
Int32 | 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(Int32, NativeArrayOptions)
Sets the length, expanding the capacity if necessary.
Declaration
public void Resize(int length, NativeArrayOptions options = NativeArrayOptions.UninitializedMemory)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The new length. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
SetCapacity(Int32)
Sets the capacity.
Declaration
public void SetCapacity(int capacity)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The new capacity. |
TrimExcess()
Sets the capacity to match the length.
Declaration
public void TrimExcess()