在C#中大阵的算术 [英] Large array arithmetics in C#
问题描述
这是存储,才能在C#中的二维数组的数组中的元素?
Which is the best way to store a 2D array in c# in order to optimize performance when performing lots of arithmetic on the elements in the array?
我们有很大的(约1.5克)数组,例如我们想通过元素相互元素相乘。性能是至关重要的。在这样做的背景是在C#。是否有存储阵列,并遍历其中的任何聪明的办法?我们可以写在非托管C ++这些部件,并将这真的提高性能?该阵列必须到C#程序的其余部分进行访问。
We have large (approx 1.5G) arrays, which for example we want to multiply with each other element by element. Performance is critical. The context in which this is done is in c#. Is there any smart way of storing the arrays and iterating over them? Could we write these parts in unmanaged C++ and will this really increase performance? The arrays need to be accessible to the rest of the c# program.
目前(在c)该数组存储为单个长向量。我们数组中的每个元素进行计算并覆盖旧值。计算通常是在向量中的每个元素是唯一的。
Currently (in c) the array is stored as a single long vector. We perform calculations on each element in the array and overwrite the old value. The calculations are usually unique for each element in the vector.
时序实验表明,存储和遍历数据,在C#中的数组比把它作为一个二维数组慢。我想知道是否有处理数据的更好的方法。执行的特定算术是不相关的问题。
Timing experiments show that storing and iterating over the data as an array in C# is slower than storing it as a 2D array. I would like to know if there is an even better way of handling the data. The specific arithmetics performed are not relevant for the question.
推荐答案
安娜,
下面是一个讨论的传统科学的编程语言(FORTRAN,C ++)和C#之间的性能差异很大的页面。
Here is a great page that discusses the performance difference between tradition scientific programming languages (fortran, C++) and c#.
<一个href=\"http://msdn.microsoft.com/en-us/magazine/cc163995.aspx\">http://msdn.microsoft.com/en-us/magazine/cc163995.aspx
根据文章C#,使用矩形阵列(2D)时,可以是一个很好的演员。这里是表示在交错数组(数组的数组)和矩形阵列(多维)阵列
According to the article C#, when using rectangular arrays (2d) can be a very good performer. Here is a graph that shows the difference in performance between jagged arrays (an array of arrays) and rectangular arrays (multi-dimensional) arrays.
我建议尝试自己,并使用性能分析在VS 2008比较。
I would suggest experimenting yourself, and use the Performance Analysis in VS 2008 to compare.
如果使用C#是不够快,那么你的应用程序将是更易于维护。
If using C# is "fast enough" then your application will be that much easier to maintain.
祝您好运!
这篇关于在C#中大阵的算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!