Stack overflow visual C++, potentially array size?(堆栈溢出视觉 C++,可能是数组大小?)
问题描述
据我所知,这不是无限递归造成的.
As far as I know, this isn't caused by an infinite recursion.
程序在较小的数组中正常运行(它是一个音频编辑器).现在我增加了功能以允许更大的数组(最多 5 分钟的音频,26460000 条 16 位数据 ~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.
任何帮助将不胜感激,我确信有一个足够简单的解决方案(我读过涉及堆"的内容,但我不确定堆"到底是什么).
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).
推荐答案
正如 Vlad 指出,不要分配堆栈上有 50MB.
As Vlad pointed out, don't allocate 50MB on the stack.
但是,这一点没有实际意义,因为您不需要分配 任何 数据.尝试通过一次调用 std::reverse来替换整个代码片段代码>:
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 <algorithm>.
这篇关于堆栈溢出视觉 C++,可能是数组大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:堆栈溢出视觉 C++,可能是数组大小?
基础教程推荐
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
