堆栈溢出VISUAL C ++,潜在数组的大小? [英] Stack overflow visual C++, potentially array size?

查看:202
本文介绍了堆栈溢出VISUAL C ++,潜在数组的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,这是不是一个无限递归造成的。

As far as I know, this isn't caused by an infinite recursion.

该方案具有较小的数组(这是一个音频编辑器)正确运作。现在,我已经增加了功能,允许更大的阵列(最多5分钟的音频,2646万个16bit的数据50MB〜的)。

The program functioned correctly with smaller arrays (it is an audio editor). Now I have increased functionality to allow for larger arrays (up to 5 minutes of audio, 26460000 pieces of 16bit data ~50mb).

由于增加阵列的尺寸,我在一个特定的功能,它应该由阵列写入到一个新的数组倒退,然后重写原数组反向输入文件的播放接收堆栈溢出错误。我猜每个阵列可高达50MB,这可能是问题的症结所在:

Since increasing the array's size I am receiving stack overflow errors on one particular function, where it should reverse the playback of an input file by writing the array into a new array backwards, then overwriting the original array. I'm guessing as each array could be up to 50MB this may be where the problem lies:

//initialise temporary new array to place samples in
short signed int reverse_data[max_number_samples];  

for (i=0; i<track_samples; i++)
{  //puts data from sound_data into reverse_data backwards.
  reverse_data[(max_number_samples-1)-i]=sound_data[i];    
}

for (i=0; i<track_samples; i++)    
{     //now overwrites sound_data with the data in reverse_data
  sound_data[i]=reverse_data[i];
}

我是相当新的C ++,和一般的编程,和我不确定什么调试过程中出现了错误真的告诉我。

I'm fairly new to C++, and programming in general, and am unsure of what the errors I get during debug are really telling me.

任何帮助将是AP preciated,我敢肯定有一个很简单的解决方案(我读过的东西,涉及'堆',但我不相信什么a'heap'确实是)。

Any help would be appreciated, I'm sure there's a simple enough solution (I've read stuff involving 'heaps' but I'm not confident of what a'heap' really is).

推荐答案

由于弗拉德指出,不分配50MB的堆栈。

As Vlad pointed out, don't allocate 50MB on the stack.

不过,问题是没有实际意义,因为你并不需要分配的任何的数据。尝试用一个调用替换整个code片段 <为code>的std ::逆转

But, the point is moot because you don't need to allocate any data. Try replacing your entire code fragment with a single call to std::reverse:

std::reverse(&sound_data[0], &sound_data[track_samples]);



后记的:不要忘了的#include&LT;&算法GT;

这篇关于堆栈溢出VISUAL C ++,潜在数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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