public unsafe void Test_BigArray() { Console.WriteLine("Size of element: {0}, sizeof IntPtr: {1}", sizeof(TestStruct), sizeof(IntPtr)); Int64 arrSize = 200 * 1000000; Int64 byteSize = (Int64)(arrSize * (Int64)sizeof(TestStruct)); Console.WriteLine("Allocating {0:#,#} bytes...", byteSize); TestStruct *pArray = (TestStruct *)UnmanagedMemory.AllocHGlobalEx(byteSize); Console.WriteLine("Allocated {0:#,#} bytes", byteSize); pArray[0].data[0] = 1; Console.WriteLine("Filling with data..."); for (Int64 i = 0; i < arrSize; ++i) { pArray[i].data[0] = 10; } Console.WriteLine("Freeing memory"); UnmanagedMemory.FreeHGlobal(pArray); }
/// <summary> /// Allocate memory for arrays. Must be called when n, dim and k are set. /// </summary> public void Allocate() { points = (double *)UnmanagedMemory.AllocHGlobalEx(n * dim * 8); centers = (double *)UnmanagedMemory.AllocHGlobalEx(k * dim * 8); }