public static void *MallocAndClear(long size, int alignment = 8, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { var memory = UnsafeUtility.Malloc(size, alignment, allocator); UnsafeUtility.MemClear(memory, size); return(memory); }
public static T *MallocAndClear <T>(Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { var memory = UnsafeUtility.Malloc(sizeof(T), GetAlignment <T>(), allocator); UnsafeUtility.MemClear(memory, sizeof(T)); return((T *)memory); }
static object PerformMemberwiseClone(ref object o) { var ins = new Unity.Collections.Allocator(); ins = (Unity.Collections.Allocator)o; return(ins); }
public NativeQueue(int size, Unity.Collections.Allocator allocator) { this.arr = new Unity.Collections.NativeList <T>(size, allocator); this.Count = 0; this.head = -1; this.last = -1; }
//[MethodImplAttribute(MethodImplOptions.AggressiveInlining)] public static T *Create <T>(ref T *ptr, ref T source, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { var size = UnsafeUtility.SizeOf <T>(); ptr = (T *)System.Runtime.InteropServices.Marshal.AllocHGlobal(size); //ptr = (T*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf<T>(), UnsafeUtility.AlignOf<T>(), allocator); UnsafeUtility.CopyStructureToPtr(ref source, ptr); return(ptr); }
public static T *Create <T>(Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { var size = UnsafeUtility.SizeOf <T>(); var ptr = (T *)System.Runtime.InteropServices.Marshal.AllocHGlobal(size); //var ptr = UnsafeUtility.Malloc(size, UnsafeUtility.AlignOf<T>(), allocator); UnsafeUtility.MemClear(ptr, size); return(ptr); }
//[MethodImplAttribute(MethodImplOptions.AggressiveInlining)] public static void *CreateFromStruct <T>(ref T source, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : struct { var size = UnsafeUtility.SizeOf <T>(); var ptr = (void *)System.Runtime.InteropServices.Marshal.AllocHGlobal(size); //var ptr = UnsafeUtility.Malloc(UnsafeUtility.SizeOf<T>(), UnsafeUtility.AlignOf<T>(), allocator); UnsafeUtility.CopyStructureToPtr(ref source, ptr); return(ptr); }
public static NativeBufferArray <T> Spawn(int length, bool realSize = false, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { var arrSize = PoolArray <T> .GetSize(length); var arr = new Unity.Collections.NativeArray <T>(arrSize, allocator); var size = (realSize == true ? arr.Length : length); var buffer = new NativeBufferArray <T>(arr, length, realSize == true ? arr.Length : -1); NativeArrayUtils.Clear(buffer, 0, size); return(buffer); }
static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref Unity.Collections.Allocator instance_of_this_method) { ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.Object: { __mStack[ptr_of_this_method->Value] = instance_of_this_method; } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { var t = __domain.GetType(___obj.GetType()) as CLRType; t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method); } } break; case ObjectTypes.StaticFieldReference: { var t = __domain.GetType(ptr_of_this_method->Value); if (t is ILType) { ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as Unity.Collections.Allocator[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method; } break; } }
public DynamicTree(Allocator allocator) { _allocator = allocator; _root = NullNode; _nodeCapacity = 16; _nodeCount = 0; _nodes = (Node *)Util.Malloc <Node>(_nodeCapacity, allocator); UnsafeUtility.MemClear(_nodes, _nodeCapacity * sizeof(Node)); // Build a linked list for the free list. for (var i = 0; i < _nodeCapacity - 1; ++i) { _nodes[i].Next = i + 1; _nodes[i].Height = -1; } _nodes[_nodeCapacity - 1].Next = NullNode; _nodes[_nodeCapacity - 1].Height = -1; _freeList = 0; _insertionCount = 0; }
public DataBuffer(World world, ME.ECS.Collections.NativeBufferArray <Entity> arr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { var reg = (StructComponents <T>)world.currentState.structComponents.list.arr[WorldUtilities.GetAllComponentTypeId <T>()]; this.arr = new NativeArrayBurst <T>(reg.components.data.arr, allocator); this.ops = new NativeArrayBurst <byte>(reg.components.data.arr.Length, allocator); }
public static bool Resize <T>(int index, ref Unity.Collections.NativeHashSet <T> arr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent, bool resizeWithOffset = false) where T : unmanaged, System.IEquatable <T> { int offset = 1; if (resizeWithOffset == true) { offset *= 2; } var capacity = index * offset + 1; if (arr.IsCreated == false) { arr = new Unity.Collections.NativeHashSet <T>(capacity, allocator); } if (capacity > arr.Capacity) { arr.Capacity = capacity; return(true); } return(false); }
public override TrackableChanges <XRHumanBody> GetChanges(XRHumanBody defaultHumanBody, Unity.Collections.Allocator allocator) { return(new TrackableChanges <XRHumanBody>()); }
public static void *Malloc(long size, int alignment = 8, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { return(UnsafeUtility.Malloc(size, alignment, allocator)); }
public static void Free(void *memory, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { UnsafeUtility.Free(memory, allocator); }
public static T *tnew <T>(Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { return(MemUtils.Create <T>(allocator)); }
//[MethodImplAttribute(MethodImplOptions.AggressiveInlining)] public static T *tnew <T>(ref T *ptr, ref T source, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { return(MemUtils.Create(ref ptr, ref source, allocator)); }
public static void *pnew <T>(ref void *ptr, ref T source, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : struct { return(MemUtils.CreateFromStruct(ref ptr, ref source, allocator)); }
public static void *pnew <T>(Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : struct { return(MemUtils.CreateFromStruct <T>(allocator)); }
public static void free <T>(ref T *ptr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { //UnsafeUtility.Free(ptr, allocator); System.Runtime.InteropServices.Marshal.FreeHGlobal((System.IntPtr)ptr); ptr = null; }
public static unsafe bool Resize <T>(int index, ref Unity.Collections.NativeList <T> arr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { const int offset = 1; if (arr.IsCreated == false) { arr = new Unity.Collections.NativeList <T>(index * offset + 1, allocator); } if (index < arr.Length) { return(false); } var newLength = arr.Length * offset + 1; if (newLength == 0 || newLength <= index) { newLength = index * offset + 1; } var elements = newLength - arr.Length; //var ptr = (void*)((System.IntPtr)arr.GetUnsafePtr() + UnsafeUtility.SizeOf<T>() * arr.Length); for (int i = 0; i < elements; ++i) { arr.Add(default);
public static T *Malloc <T>(Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : unmanaged { return((T *)UnsafeUtility.Malloc(sizeof(T), GetAlignment <T>(), allocator)); }
public static bool Resize <T>(int index, ref Unity.Collections.NativeArray <T> arr, bool resizeWithOffset = true, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) where T : struct { var offset = (resizeWithOffset == true ? 2 : 1); if (arr.IsCreated == false) { arr = new Unity.Collections.NativeArray <T>(index * offset + 1, allocator); } if (index < arr.Length) { return(false); } var newLength = arr.Length * offset + 1; if (newLength == 0 || newLength <= index) { newLength = index * offset + 1; } var newArr = new Unity.Collections.NativeArray <T>(newLength, allocator); Unity.Collections.NativeArray <T> .Copy(arr, 0, newArr, 0, arr.Length); arr.Dispose(); arr = newArr; return(true); }
/// <summary> /// If min queue or max queue /// </summary> /// <param name="isMinPriorityQueue"></param> public PriorityQueueNative(Unity.Collections.Allocator allocator, int capacity = 4, bool isMinPriorityQueue = false) { this.heapSize = -1; this.isMinPriorityQueue = isMinPriorityQueue == true ? (byte)1 : (byte)0; this.queue = new Unity.Collections.NativeList <Node>(capacity, allocator); }