相关疑难解决方法(0)

Array.Copy与Buffer.BlockCopy

Array.CopyBuffer.BlockCopy都做同样的事情,但是BlockCopy针对快速字节级原始数组复制,而是Copy通用实现.我的问题是 - 在什么情况下你应该使用BlockCopy?您是否应该在复制基本类型数组时随时使用它,或者只有在编写性能时才使用它?使用Buffer.BlockCopy结束有什么固有的危险Array.Copy吗?

.net arrays

119
推荐指数
6
解决办法
7万
查看次数

有没有更快的方法在C#中复制数组?

我有三个阵列需要组合在一个三维数组中.以下代码显示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)

c# arrays copy

32
推荐指数
4
解决办法
5万
查看次数

标签 统计

arrays ×2

.net ×1

c# ×1

copy ×1