Array.Copy和Buffer.BlockCopy都做同样的事情,但是BlockCopy针对快速字节级原始数组复制,而是Copy通用实现.我的问题是 - 在什么情况下你应该使用BlockCopy?您是否应该在复制基本类型数组时随时使用它,或者只有在编写性能时才使用它?使用Buffer.BlockCopy结束有什么固有的危险Array.Copy吗?
我有三个阵列需要组合在一个三维数组中.以下代码显示Performance Explorer中的性能降低.有更快的解决方案吗?
for (int i = 0; i < sortedIndex.Length; i++) {
if (i < num_in_left)
{
// add instance to the left child
leftnode[i, 0] = sortedIndex[i];
leftnode[i, 1] = sortedInstances[i];
leftnode[i, 2] = sortedLabels[i];
}
else
{
// add instance to the right child
rightnode[i-num_in_left, 0] = sortedIndex[i];
rightnode[i-num_in_left, 1] = sortedInstances[i];
rightnode[i-num_in_left, 2] = sortedLabels[i];
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
我其实是在尝试做以下事情:
//given three 1d arrays
double[] sortedIndex, sortedInstances, sortedLabels;
// copy them over to a 3d array (forget about …Run Code Online (Sandbox Code Playgroud)