程序中的堆栈溢出错误

程序中的堆栈溢出错误

本文介绍了C ++程序中的堆栈溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个复杂的类,我想有一个二维数组的复数,这是代码的一部分,而不是所有的代码

So i have this complex class , and i want to have an 2d array of complex numbers this is part of the code not all the code

class Complex {
public:
    /* construction/destruction */
    Complex(double r, double i)     { this->r = r; this->i = i; }
    Complex()                       { r=0.0; i=0.0; }
    ~Complex()                      { r=0.0; i=0.0; }
        /* operations */
    Complex operator+(Complex &c)   { return Complex( r+c.r, i+c.i ); }
        double r, i;
};

int main()
{
const int HEIGHT = 256;
const int WIDTH = 256;
Complex G[HEIGHT][WIDTH];
}

所以行G [HEIGHT] [WIDTH];

so the line Complex G[HEIGHT][WIDTH]; is the line that causes the problem , any idea why ?

推荐答案

Visual studio默认为1MB堆栈大小,它看起来像: / p>

Visual studio defaults to 1MB stack size, it looks like:

Complex G[HEIGHT][WIDTH];

将大约为1MB,您可以使用和文档说明(强调我的) :

will be just about 1MB, you can modify this using /F and the document says (emphasis mine):

最明显的替代方法是通过 new 或。

The most obvious alternative would be to use dynamic memory allocation via new or std::vector.

据我所知,实际上有堆栈大小之一:

Visual Studio as far as I know actually has one of the smaller default stack sizes:

platform    default size
=====================================
SunOS/Solaris  8192K bytes
Linux          8192K bytes
Windows        1024K bytes
cygwin         2048K bytes
Mac OS X       8192K bytes

这篇关于C ++程序中的堆栈溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:46