Visual C ++和大型2d数组 [英] Visual C++ and large 2d arrays

查看:56
本文介绍了Visual C ++和大型2d数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我已经制作了一个2d动态数组,如下所示(这是一个片段,所以并非所有的

变量都被计算在内) :


// numvoices是动态的(1-1000),由用户输入

// MAXCHANNELS目前被定义为24

float ** gvoiceSpat;

float ** notechannelGain;

float ** notechannelGainSpread;


gvoiceSpat = new float * [numvoices];

notechannelGain = new float * [numvoices];

notechannelGainSpread = new float * [numvoices];


for(i = 0; i< numvoices; i ++)

{

gvoiceSpat [i] = new float [MAXCHANNELS];

notechannelGain [i] = new float [MAXCHANNELS];

notechannelGainSpread [i] = new float [MAXCHANNELS];

}


有趣的是,这段代码在gcc中完美无缺,但是在
Visual C ++(2003 .NET)中,当数字超过〜120时,程序

崩溃,有时候报告未知的例外。问题是

这是另一个应用程序的外部模块的代码,并使用

额外的第三方库,因此很难指出

罪魁祸首。然而,事实仍然是这种崩溃只发生在使用Visual C ++的Windows

上,而它在使用相同的库的OSX(gcc)和Linux

(gcc)上完美运行。


关于为什么会出现这种情况的任何想法?


对于它的价值,我也尝试用向量代替这些与

没有任何区别。


非常感谢任何帮助!


此致,


Ico

Hi all,

I''ve made a 2d dynamic array as follows (this is a snippet so not all
variables are accounted for):

//numvoices are dynamic (1-1000), entered by user
//MAXCHANNELS is currently defined as 24

float **gvoiceSpat;
float **notechannelGain;
float **notechannelGainSpread;

gvoiceSpat = new float *[numvoices];
notechannelGain = new float *[numvoices];
notechannelGainSpread = new float *[numvoices];

for (i = 0; i < numvoices; i++)
{
gvoiceSpat[i] = new float[MAXCHANNELS];
notechannelGain[i] = new float[MAXCHANNELS];
notechannelGainSpread[i] = new float[MAXCHANNELS];
}

The interesting thing is that this code works flawlessly in gcc but in
Visual C++ (2003 .NET) whenever numvoices exceeds ~120, the program
crashes, sometimes reporting unknown exception. The problem is that
this is a code for an external module for another application and uses
additional third-party libs so it is difficult to point fingers at the
culprit. Yet, the fact remains that this crash occurs only on Windows
using Visual C++, while it works flawlessly on OSX (gcc) and Linux
(gcc) using same libs.

Any ideas as to why would this be the case?

For what it''s worth, I also tried substituting these with vectors with
no difference whatsoever.

Any help is most appreciated!

Sincerely,

Ico

推荐答案



On 5/2/07 6:44 PM,文章
11 *** *******************@n76g2000hsh.googlegroups。 com

" ic ******** @ gmail.com" < ic ******** @ gmail.comwrote:

On 5/2/07 6:44 PM, in article
11**********************@n76g2000hsh.googlegroups. com,
"ic********@gmail.com" <ic********@gmail.comwrote:

我已经制作了一个2d动态数组,如下所示(这是一个片段,所以不是所有

变量都计入):


// numvoices是动态的(1-1000),由用户输入

/ / MAXCHANNELS目前被定义为24

float ** gvoiceSpat;

float ** notechannelGain;

float ** notechannelGainSpread;


gvoiceSpat = new float * [numvoices];

notechannelGain = new float * [numvoices];

notechannelGainSpread = new float * [numvoices];


for(i = 0; i< numvoices; i ++)

{

gvoiceSpat [i ] = new float [MAXCHANNELS];

notechannelGain [i] = new float [MAXCHANNELS];

notechannelGainSpread [i] = new float [MAXCHANNELS];

}


有趣的是,这个代码在gcc中完美无缺,但是只要数字超过〜120,就可以在
Visual C ++(2003 .NET)中运行,th e程序

崩溃,有时报告未知异常。问题是

这是另一个应用程序的外部模块的代码,并使用

额外的第三方库,因此很难指出

罪魁祸首。然而,事实仍然是这种崩溃只发生在使用Visual C ++的Windows

上,而它在使用相同的库的OSX(gcc)和Linux

(gcc)上完美运行。


关于为什么会出现这种情况的任何想法?
I''ve made a 2d dynamic array as follows (this is a snippet so not all
variables are accounted for):

//numvoices are dynamic (1-1000), entered by user
//MAXCHANNELS is currently defined as 24

float **gvoiceSpat;
float **notechannelGain;
float **notechannelGainSpread;

gvoiceSpat = new float *[numvoices];
notechannelGain = new float *[numvoices];
notechannelGainSpread = new float *[numvoices];

for (i = 0; i < numvoices; i++)
{
gvoiceSpat[i] = new float[MAXCHANNELS];
notechannelGain[i] = new float[MAXCHANNELS];
notechannelGainSpread[i] = new float[MAXCHANNELS];
}

The interesting thing is that this code works flawlessly in gcc but in
Visual C++ (2003 .NET) whenever numvoices exceeds ~120, the program
crashes, sometimes reporting unknown exception. The problem is that
this is a code for an external module for another application and uses
additional third-party libs so it is difficult to point fingers at the
culprit. Yet, the fact remains that this crash occurs only on Windows
using Visual C++, while it works flawlessly on OSX (gcc) and Linux
(gcc) using same libs.

Any ideas as to why would this be the case?



可能是在Windows上,numvoices是一个字符 - 当数字的值超过128并且溢出时,程序是
崩溃?


Greg

Could it be that on Windows numvoices is a char - and the program is
crashing when numvoices'' value exceeds 128 and overflows?

Greg



关于为什么会出现这种情况的任何想法?
Any ideas as to why would this be the case?



可能是Windows上的numvoices是一个字符 - 而且当numvoices的值超过128并且溢出时程序是
崩溃?


Greg


Could it be that on Windows numvoices is a char - and the program is
crashing when numvoices'' value exceeds 128 and overflows?

Greg



不知道。如何测试和/或减轻它?


Ico

No idea. How can this be tested and/or alleviated?

Ico


实际上,经过仔细检查,天花板似乎会移动很多

和优化代码确实增加了它(没有代码优化它

徘徊在90左右,并且通过完全优化它可以达到120或

so)。


Ico

Actually, upon closer inspection, the ceiling appears to shift a lot
and optimizing code does increase it (without code optimization it
hovers around 90, and with full optimization it can get up to 120 or
so).

Ico


这篇关于Visual C ++和大型2d数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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