Documentation

Unity Engine

Unity Engine

DynamicBuffer<T>

An array-like data structure that can be used as a component.
Read time 2 minutesLast updated 4 days ago

Definition

public struct DynamicBuffer<T> : IQueryTypeParameter, IEnumerable<T>, IEnumerable, INativeList<T>, IIndexable<T> where T : unmanaged

Properties

Property

Description

CapacityThe number of elements the buffer can hold.
IsCreatedWhether the memory for this dynamic buffer has been allocated.
IsEmptyReports whether container is empty.
this[]Array-like indexing operator.
LengthThe number of elements the buffer holds.

Methods

Method

Description

AddAdds an element to the end of the buffer, resizing as necessary.
AddRangeAdds all the elements from
newElems
to the end of the buffer, resizing as necessary.
AsNativeArrayReturn a native array that aliases the original buffer contents.
ClearSets the buffer length to zero.
CopyFromCopies all the elements from an array.
ElementAtGets the reference to the element at the given index.
EnsureCapacityEnsures that the buffer has at least the specified capacity.
GetEnumeratorProvides an enumerator for iterating over the buffer elements.
GetUnsafePtrGets an
unsafe
read/write pointer to the contents of the buffer.
GetUnsafeReadOnlyPtrGets an
unsafe
read-only pointer to the contents of the buffer.
InsertInserts an element at the specified index, resizing as necessary.
ReinterpretReturns a dynamic buffer of a different type, pointing to the same buffer memory.
RemoveAtRemoves the element at the specified index.
RemoveAtSwapBackRemoves the element at the specified index and swaps the last element into its place. This is more efficient than moving all elements following the removed element, but does change the order of elements in the buffer.
RemoveRangeRemoves the specified number of elements, starting with the element at the specified index.
RemoveRangeSwapBackRemoves the specified number of elements, starting with the element at the specified index. It replaces the elements that were removed with a range of elements from the back of the buffer. This is more efficient than moving all elements following the removed elements, but does change the order of elements in the buffer.
ResizeSets the length of this buffer, increasing the capacity if necessary.
ResizeUninitializedSets the length of this buffer, increasing the capacity if necessary.
ToNativeArrayCopies the buffer into a new native array.
TrimExcessRemoves any excess capacity in the buffer.