// TODO: Fix this to make no memory allocations. public void PublicConstructorCallTest() { ClassAllocator.PreCacheConstructor <DummyClass>(); //using (MemoryRestrictor.StartNoAlloc()) using (ClassAllocator.Allocate(out DummyClass uheapObj)) { //MemoryRestrictor.EndNoAlloc(); Assert.AreEqual(DummyClass.DefaultConstructorIntField, uheapObj.IntField); } }
public void Int32BoxingTest() { using (MemoryRestrictor.StartNoAlloc()) { int val = 12345678; using (ClassAllocator.Box(val, out Object boxed)) { MemoryRestrictor.EndNoAlloc(); Assert.AreEqual(val, boxed); } } }
public AllocationFreeList() { unsafe { listHandle = ClassAllocator.UninitializedAllocation(out list); ppItems = (IntPtr)((Byte *)listHandle.ObjHeader + sizeof(ObjectHeader)); pSize = ppItems + sizeof(IntPtr); pVersion = pSize + sizeof(Int32); } items = EmptyArray; }
public unsafe AllocationFreeList(int capacity) : this() { if (capacity == 0) { items = EmptyArray; } else { arrayHandle = ClassAllocator.AllocateSZArray(capacity, out T[] temp); items = temp; } }
public void PrimitiveOperation() { Random rd = new Random(); int size = rd.Next(1000, 2000); int[] original = new int[size]; for (int idx = 0; idx < original.Length; idx++) { original[idx] = rd.Next(); } using (MemoryRestrictor.StartNoAlloc()) using (ClassAllocator.AllocateSZArray(size, out int[] arr))
public void OperationTest() { const int maxCapacity = 2048; Random rd = new Random(); List <int> list1 = new List <int>(maxCapacity); ClassAllocator.PreCacheConstructor <AllocationFreeList <int> >(); using (ClassAllocator.Allocate(out AllocationFreeList <int> list2)) { for (int iter = 0; iter < 100000; iter++) { switch (rd.Next() % 2) { case 0: if (list1.Count == maxCapacity) { break; } int val = rd.Next(); list1.Add(val); list2.Add(val); break; case 1: if (list1.Count == 0) { break; } int index = rd.Next() % list1.Count; list1.RemoveAt(index); list2.RemoveAt(index); break; } Assert.AreEqual(list1.Count, list2.Count); for (int idx = 0; idx < list1.Count; idx++) { Assert.AreEqual(list1[idx], list2[idx]); } } } }
static AllocationFreeList() { // Note: emptyArray will not be free in any case. ClassAllocator.AllocateSZArray <T>(0, out EmptyArray); }