Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


UnsafeList<T>

An unmanaged, resizable list.
Read time 3 minutesLast updated 2 days ago

Definition

public struct UnsafeList<T> : INativeDisposable, IDisposable, INativeList<T>, IIndexable<T>, IEnumerable<T>, IEnumerable where T : unmanaged

Fields

Value

Description

AllocatorThe allocator used to create the internal buffer.
m_capacityThe number of elements that can fit in the internal buffer.
m_lengthThe number of elements.
PtrThe internal buffer of this list.

Static Fields

Value

Description

MaxCapacityThe maximum number of elements this type of container can hold.

Constructors

Constructor

Description

UnsafeList`1(`0*,System.Int32)Initializes and returns an instance of UnsafeList.
UnsafeList`1(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle,Unity.Collections.NativeArrayOptions)Initializes and returns an instance of UnsafeList.

Properties

Property

Description

CapacityThe number of elements that can fit in the internal buffer.
IsCreatedWhether this list has been allocated (and not yet deallocated).
IsEmptyWhether the list is empty.
this[]The element at an index.
LengthThe number of elements.

Methods

Method

Description

AddAdds an element to the end of the list.
AddNoResizeAdds an element to the end of this list.
AddRangeCopies elements from a ReadOnlySpan to the end of this list.
AddRangeNoResizeCopies elements from a ReadOnlySpan to the end of this list.
AddReplicateAppends value count times to the end of this list.
AsParallelReaderObsolete. Use UnsafeList<T>.AsReadOnly instead.
AsParallelWriterReturns a parallel writer of this list.
AsReadOnlyReturns a read only of this list.
AsReadOnlySpanReturns ReadOnlySpan\<T\> view of this container.
AsSpanReturns Span\<T\> view of this container.
ClearSets the length to 0.
CopyFromCopies all elements of specified container to this container.
DisposeReleases all resources (memory).
ElementAtReturns a reference to the element at a given index.
GetEnumeratorReturns an enumerator over the elements of the list.
GetUnsafePtrGet a pointer to the data.
GetUnsafeReadOnlyPtrGet a pointer to the data.
InsertRangeShifts elements toward the end of this list, increasing its length.
InsertRangeWithBeginEndShifts elements toward the end of this list, increasing its length.
RemoveAtRemoves the element at an index, shifting everything above it down by one. Decrements the length by 1.
RemoveAtSwapBackCopies the last element of this list to the specified index. Decrements the length by 1.
RemoveRangeRemoves "N" elements in a range, shifting everything above the range down by "N". Decrements the length by "N".
RemoveRangeSwapBackCopies the last "N" elements of this list to a range in this list. Decrements the length by "N".
ResizeSets the length, expanding the capacity if necessary.
SetCapacitySets the capacity.
TrimExcessSets the capacity to match the length.

Static Methods

Method

Description

CreateReturns a new list.
DestroyDestroys the list.

Structs

Struct

Description

UnsafeList<T>.EnumeratorAn enumerator over the elements of a list.
UnsafeList<T>.ParallelReaderObsolete. Use UnsafeList<T>.ReadOnly instead.
UnsafeList<T>.ParallelWriterA parallel writer for an UnsafeList\<T\>.
UnsafeList<T>.ReadOnlyA read only for an UnsafeList\<T\>.