堆栈溢出 Visual C++,可能是数组大小? [英] Stack overflow visual C++, potentially array size?

查看:34
本文介绍了堆栈溢出 Visual 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 .

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

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