用零填充2D动态数组的最快方法 [英] The fastest way to fill 2D dynamic array with zeros

查看:68
本文介绍了用零填充2D动态数组的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在编写跨平台代码,所以我必须遵守标准。这是

我的代码:

~~~~~~~~~~~~~~~~~~

double ** mx = new double * [col - 1];

for(int i = 0; i< col - 1; i ++){

mx [i] = new double [row];

sizeOfMx + = sizeof(double)* row;

}

//我需要填写 MX"尽可能快地使用零点

~~~~~~~~~~~~~~~~~~~


所以我在评论中提到,我有一个问题,找到极其简单的方法用零填充2D动态数组。有谁知道

我可以帮助我吗?


谢谢,

-R。

推荐答案

2006年2月25日07:42:44 -0800, ro ******** @ gmail.com 写道:
On 25 Feb 2006 07:42:44 -0800, ro********@gmail.com wrote:
大家好,

我在写十字架-platform代码所以我必须遵守标准。这是我的代码:
~~~~~~~~~~~~~~~~~~
双** mx =新双* [col - 1] ;
for(int i = 0; i< col - 1; i ++){
mx [i] = new double [row];
sizeOfMx + = sizeof(double)* row ;
}
//我需要填写mx用尽可能快的零点
~~~~~~~~~~~~~~~~~~~

正如我在评论中提到的,我有问题找到用零填充2D动态数组的极快方法。有谁知道我可以帮助我的东西吗?

谢谢,
-R。
Hello All,

I''m writing cross-platform code so i''m bound to standards. Here is
the code I have:
~~~~~~~~~~~~~~~~~~
double **mx = new double*[col - 1];
for(int i = 0; i < col - 1; i++) {
mx[i] = new double[row];
sizeOfMx += sizeof(double) * row;
}
//I need to fill "mx" with zeros as fast as it is possible
~~~~~~~~~~~~~~~~~~~

So as I mentioned in comment, i have problem with finding the extremely
fast way to fill the 2D dynamic array with zeros. Does anyone know
something I that might help me?

Thanks,
-R.




它会是更快地计算行*列并在一次调用new []时分配你的2D

数组,好像它是一维数组,而不是做一个新的[]
每列。然后你可以使用

for循环初始化元素,就好像它是一维数组一样。我不知道使用循环是否是最快的方式,但所有那些新的[]调用可能会更加昂贵。

更贵。


如果你有数百万或数十亿的双打,你可能想把内存分成几个桶并分配一些线程来初始化

他们并行。但这不是平台无关的,所以

我只会使用循环。


可能最好的想法是使用std ::矢量<双>对待它

就像一个数组......这样你就不必在你的

阵列上调用delete []了。


在他的书更有效的C ++中,Scott Meyers也对其实施2D阵列进行了处理。

。 Google forc ++和2D阵列。并且

你会得到很多点击。


-

Bob Hairgrove
没有********** @ Home.com

ro********@gmail.com 写道:
大家好,

我正在编写跨平台代码,所以我必须遵守标准。这是我的代码:


看看矩阵 " C ++"在谷歌。

~~~~~~~~~~~~~~~~~~
双** mx =新双* [col - 1];
for(int i = 0; i< col - 1; i ++){
mx [i] = new double [row];
sizeOfMx + = sizeof(double)* row;
}
//我需要填写mx用尽可能快的零点
~~~~~~~~~~~~~~~~~~~

正如我在评论中提到的,我有问题找到用零填充2D动态数组的极快方法。有谁知道我可以帮助我的东西?
Hello All,

I''m writing cross-platform code so i''m bound to standards. Here is
the code I have:
Look at "matrix" "C++" on google.
~~~~~~~~~~~~~~~~~~
double **mx = new double*[col - 1];
for(int i = 0; i < col - 1; i++) {
mx[i] = new double[row];
sizeOfMx += sizeof(double) * row;
}
//I need to fill "mx" with zeros as fast as it is possible
~~~~~~~~~~~~~~~~~~~

So as I mentioned in comment, i have problem with finding the extremely
fast way to fill the 2D dynamic array with zeros. Does anyone know
something I that might help me?




这些阵列有多大?



How big are these arrays going to be ?

Gianni Mariani写道:
Gianni Mariani wrote:
ro ******** @ gmail。 com 写道:
Hello All,

我正在编写跨平台代码,所以我必须遵守标准。这是我的代码:
看看矩阵 " C ++"在google上。
Hello All,

I''m writing cross-platform code so i''m bound to standards. Here is
the code I have:
Look at "matrix" "C++" on google.
~~~~~~~~~~~~~~~~~~
double ** mx = new double * [col - 1] ;


我没有看到有人提到这个,但你为什么要分配

比看起来像列数少一个?

for(int i = 0; i< col - 1; i ++){
mx [i] = new double [row];
sizeOfMx + = sizeof(double )*行;
}
//我需要填写mx用尽可能快的零点
~~~~~~~~~~~~~~~~~~~

正如我在评论中提到的,我有问题找到用零填充2D动态数组的极快方法。是否有人知道我可以帮助我的事情?
~~~~~~~~~~~~~~~~~~
double **mx = new double*[col - 1];
I didn''t see anybody mention this, but why are you allocating
one less than what seems to be the "number of columns"?
for(int i = 0; i < col - 1; i++) {
mx[i] = new double[row];
sizeOfMx += sizeof(double) * row;
}
//I need to fill "mx" with zeros as fast as it is possible
~~~~~~~~~~~~~~~~~~~

So as I mentioned in comment, i have problem with finding the
extremely fast way to fill the 2D dynamic array with zeros. Does
anyone know something I that might help me?




是的,如果你这样做


mx [i] = new double [row]();


(注意括号后面的括号),然后该数组的元素

将值初始化,双倍它

表示零初始化。请注意,并非所有编译器都能够处理该语法(令人惊讶的是)


这些阵列有多大?



Yes, if you do

mx[i] = new double[row]();

(notice the parentheses after the brackets), then the elements
of that array shall be value-initialised, and for ''double'' it
means zero-initialised. Beware, not all compilers are capable
of handling that syntax (surprisingly).
How big are these arrays going to be ?




为什么要重要,Gianni?


V

-

请从我的资金中移除资金通过邮件回复时的地址



Why should it matter, Gianni?

V
--
Please remove capital As from my address when replying by mail


这篇关于用零填充2D动态数组的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆