// // Perform the equivalent of a "newarr" The resulting array is zero-initialized. // // Note that invoking NewMultiDimArray on a rank-1 array type is not the same thing as invoking NewArray(). // // As a concession to the fact that we don't actually support non-zero lower bounds, "lowerBounds" accepts "null" // to avoid unnecessary array allocations by the caller. // public static unsafe Array NewMultiDimArray(RuntimeTypeHandle typeHandleForArrayType, int[] lengths, int[] lowerBounds) { Debug.Assert(lengths != null); Debug.Assert(lowerBounds == null || lowerBounds.Length == lengths.Length); if (lowerBounds != null) { foreach (int lowerBound in lowerBounds) { if (lowerBound != 0) { throw new PlatformNotSupportedException(SR.Arg_NotSupportedNonZeroLowerBound); } } } #if REAL_MULTIDIM_ARRAYS // Create a local copy of the lenghts that cannot be motified by the caller int *pLengths = stackalloc int[lengths.Length]; for (int i = 0; i < lengths.Length; i++) { pLengths[i] = lengths[i]; } return(Array.NewMultiDimArray(typeHandleForArrayType.ToEETypePtr(), pLengths, lengths.Length)); #else MDArray mdArray = (MDArray)(NewObject(typeHandleForArrayType)); mdArray.MDInitialize(lengths); return(mdArray); #endif }
// // Perform the equivalent of a "newarr" The resulting array is zero-initialized. // // Note that invoking NewMultiDimArray on a rank-1 array type is not the same thing as invoking NewArray(). // // As a concession to the fact that we don't actually support non-zero lower bounds, "lowerBounds" accepts "null" // to avoid unnecessary array allocations by the caller. // public static Array NewMultiDimArray(RuntimeTypeHandle typeHandleForArrayType, int[] lengths, int[] lowerBounds) { Debug.Assert(lengths != null); Debug.Assert(lowerBounds == null || lowerBounds.Length == lengths.Length); if (lowerBounds != null) { foreach (int lowerBound in lowerBounds) { if (lowerBound != 0) { throw new PlatformNotSupportedException(SR.Arg_NotSupportedNonZeroLowerBound); } } } MDArray mdArray = (MDArray)(NewObject(typeHandleForArrayType)); mdArray.MDInitialize(lengths); return(mdArray); }