public void InvalidTypeTest() { var arr = UnsafeArray.Allocate <int>(10); Assert.Catch <AssertException>(() => { UnsafeArray.Set <float>(arr, 4, 20); }); UnsafeArray.Free(arr); }
public void BentimarkMyArray() { UnsafeArray <int> arr = new UnsafeArray <int>(size); for (int i = 0; i < size; i++) { arr[i] = i; } arr.Free(); }
public void BentimarkNomalToUnsafe() { int[] arr = new int[size]; var p = new UnsafeArray <int>(arr); for (int i = 0; i < size; i++) { p[i] = i; } p.Free(); }
public void ConstructorTest() { var arr = UnsafeArray.Allocate <int>(10); Assert.AreEqual(UnsafeArray.GetLength(arr), 10); for (int i = 0; i < 10; i++) { Assert.AreEqual(0, UnsafeArray.Get <int>(arr, i)); } UnsafeArray.Free(arr); }
public void MutateTest() { var arr = UnsafeArray.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeArray.Set(arr, i, i); } for (int i = 0; i < 10; i++) { Assert.AreEqual(i, UnsafeArray.Get <int>(arr, i)); } UnsafeArray.Free(arr); }
public void TestBitSet() { UnsafeBitSet *bitSet = UnsafeBitSet.Allocate(64); UnsafeBitSet.Set(bitSet, 1); UnsafeBitSet.Set(bitSet, 2); UnsafeBitSet.Set(bitSet, 3); UnsafeBitSet.Set(bitSet, 61); UnsafeArray *setBits = UnsafeArray.Allocate <int>(UnsafeBitSet.GetSize(bitSet)); var setBitsCount = UnsafeBitSet.ToArray(bitSet, setBits); for (int i = 0; i < setBitsCount; i++) { Assert.IsTrue(UnsafeBitSet.IsSet(bitSet, UnsafeArray.Get <int>(setBits, i))); } UnsafeBitSet.Free(bitSet); UnsafeArray.Free(setBits); }
public void IteratorTest() { var arr = UnsafeArray.Allocate <int>(10); unsafe { var itr = UnsafeArray.GetEnumerator <int>(arr); for (int i = 0; i < 10; i++) { UnsafeArray.Set(arr, i, i * i); } int num = 0; foreach (int i in itr) { Assert.AreEqual(num * num, i); num++; } } UnsafeArray.Free(arr); }
unsafe static void Main(string[] args) { BenchmarkDotNet.Running.BenchmarkRunner.Run <Bentimark>(); UnsafeArray <int> p0 = new UnsafeArray <int>(100); int[] arr = new int[100]; UnsafeArray <int> p1 = new UnsafeArray <int>(arr); int *p = p1.Pointer; p0.Free(); //解放時は下のうちどちらかで開放できます //つまりarrがなくてもポインタさえあれば解放できる // p1.Free(); // PointerManager.Free(p); //メイン関数にこれを置いておけば未開放分をすべて解放されます PointerManager.FreeAll(); }
public void Dispose() { UnsafeArray.Free(m_inner); m_inner = null; }