public NativeList(Allocator allocator) { Capacity = 16L; Ptr = UnsafeUtilityEx.Malloc <T>(Capacity, allocator); Length = 0L; Allocator = allocator; }
public void Clear() { if (Ptr == null) { return; } UnsafeUtilityEx.MemClear(Ptr, Length); }
public void AddOrder(Order order) { if (ordersForLaterTurn.Ptr == null) { ordersForLaterTurn = NativeEnumerable <Order> .Create(UnsafeUtilityEx.Malloc <Order>(16, Allocator.Persistent), 16); UnsafeUtility.MemClear(ordersForLaterTurn.Ptr + 1, 15 * sizeof(Order)); } else if (ordersForLaterTurnCount == ordersForLaterTurn.Length) { var newEnumerable = NativeEnumerable <Order> .Create(UnsafeUtilityEx.Malloc <Order>(ordersForLaterTurnCount << 1, Allocator.Persistent), ordersForLaterTurnCount << 1); UnsafeUtilityEx.MemCpy(newEnumerable.Ptr, ordersForLaterTurn.Ptr, ordersForLaterTurnCount); UnsafeUtility.MemClear(newEnumerable.Ptr + ordersForLaterTurnCount + 1, (ordersForLaterTurnCount - 1) * sizeof(Order)); ordersForLaterTurn.Dispose(Allocator.Persistent); ordersForLaterTurn = newEnumerable; } ordersForLaterTurn[ordersForLaterTurnCount++] = order; }
public Board(int2 size) { var count = size.x * size.y; #if DEBUG if (math.any(size < 0)) { throw new ArgumentOutOfRangeException(size.x + ", " + size.y + " should not be less than 0!"); } #endif if (math.any(size == 0)) { Cells = default; return; } Cells = NativeEnumerable <Cell> .Create(UnsafeUtilityEx.Malloc <Cell>(count, Allocator.Persistent), count); UnsafeUtility.MemClear(Cells.Ptr, count * sizeof(Cell)); }