我有三个阵列需要组合在一个三维数组中.以下代码显示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) 我正在使用Unity 4.5,将图像作为字节数组(每个字节代表一个通道,每个像素占用4个字节(rgba)并在Color32使用此循环将数组转换为数组的纹理上显示它们:
img = new Color32[byteArray.Length / nChannels]; //nChannels being 4
for (int i=0; i< img.Length; i++) {
img[i].r = byteArray[i*nChannels];
img[i].g = byteArray[i*nChannels+1];
img[i].b = byteArray[i*nChannels+2];
img[i].a = byteArray[i*nChannels+3];
}
Run Code Online (Sandbox Code Playgroud)
然后,使用以下方法将其应用于纹理:
tex.SetPixels32(img);
Run Code Online (Sandbox Code Playgroud)
但是,这会显着降低应用程序的速度(此循环在每一帧上执行),我想知道是否有其他方法可以加快复制过程.我找到了一些人(Color32 []数组的快速拷贝到byte []数组)使用这些Marshal.Copy函数来进行反向处理(Color32到字节数组),但是我还没有能够复制一个字节数组到Color32数组.有人知道更快的方式吗?
先感谢您!