Beispiel #1
0
		private static bool GetArray<ARG2, T>(
			int arg1, ARG2 arg2,
			GetArray1ArgDel<T> func1,
			GetArray2ArgDel<ARG2, T> func2,
			[Out] T[] data, int start, int count, int tupleSize)
		{
			int maxArraySize = HEU_Defines.HAPI_MAX_PAGE_SIZE / (Marshal.SizeOf(typeof(T)) * tupleSize);
			int localCount = count;
			int currentIndex = start;

			bool bResult = true;
			while (localCount > 0)
			{
				int length = 0;
				if (localCount > maxArraySize)
				{
					length = maxArraySize;
					localCount -= maxArraySize;
				}
				else
				{
					length = localCount;
					localCount = 0;
				}

				T[] localArray = new T[length * tupleSize];

				if (func1 != null)
				{
					bResult = func1(arg1, localArray, currentIndex, length);
				}
				else if (func2 != null)
				{
					bResult = func2(arg1, arg2, localArray, currentIndex, length);
				}
				else
				{
					HEU_HAPIUtility.LogError("No valid delegates given to GetArray< T >!");
					return false;
				}

				if (!bResult)
				{
					break;
				}

				// Copy from temporary array
				for (int i = currentIndex; i < (currentIndex + length); ++i)
				{
					for (int j = 0; j < tupleSize; ++j)
					{
						data[i * tupleSize + j] = localArray[(i - currentIndex) * tupleSize + j];
					}
				}

				currentIndex += length;
			}

			return bResult;
		}
		public static bool GetArray1Arg<T>(int arg1, GetArray1ArgDel<T> func, [Out] T[] data, int start, int count)
		{
			return GetArray(arg1, 0, 0, func, null, null, data, start, count, 1);
		}