111,111
社区成员




int[] array = Enumerable.Repeat<int>(10, 512 * 512).ToArray();
那这样呢
int[] array = new int[512 * 512];
array = array.Select(data => 10).ToArray();
没测试…… 不知道速度……
int Index = 1;
array[0] = 10;
fixed (int* Src = array)
{
while ((array.Length) > (1 << Index))
{
CopyMemory(Src + (1 << (Index - 1)), Src, (1 << (Index - 1)) * sizeof(int));
Index++;
}
Index--;
CopyMemory(Src + (1 << Index), Src, (array.Length - (1 << Index)) * sizeof(int));
}
其中CopyMemory的原型为:
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = true)]
internal static extern void CopyMemory(void * Dest, void * src, int Length);
我测试了5000* 5000的int数组,你那种写法时间在100ms左右,上面的约50ms。
string[] s = "".PadRight(512 * 512, '1').ToCharArray().Select(c => c.ToString()).ToArray();