using Unity.Collections; namespace Unity.XR.CoreUtils { /// /// Utility methods for working with objects. /// public static class NativeArrayUtils { /// /// Ensure that this array is large enough to contain the given capacity. /// /// /// If the array does not have sufficient capacity, it is disposed and a new, empty array is created. /// /// The type of array element. /// The array reference. Overwritten if the original array has insufficient capacity. /// The minimum number of elements that the array must be able to contain. /// The allocator to use when creating a new array, if needed. /// The options to use when creating the new array, if needed. public static void EnsureCapacity(ref NativeArray array, int capacity, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory) where T : struct { if (array.Length < capacity) { if (array.IsCreated) { array.Dispose(); } array = new NativeArray(capacity, allocator, options); } } } }