最大堆栈大小为C / C ++程序? [英] Maximum Stack Size for C/C+ Program?

查看:97
本文介绍了最大堆栈大小为C / C ++程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过下面的程序。通过此程序建立的目的是发现有关堆栈的大小了。

  INT的main()
{
    INT nStack [亿];
    返回0;
}

执行上面的code后,程序崩溃是由于巨大的堆栈大小分配。
这是堆栈的最大可能大小?难道是固定的每个程序/电脑?它可以增加?

我想知道知识的缘故。如果任何人都可以提供C / C ++的例子,那将是非常有益的。


解决方案

  

什么是堆栈的最大尺寸


重在落实。一到几兆是时下PC典型。


  

时它固定每个程序/电脑?


它通常固定在连接,但标准没有定义,它是。某些操作系统(在Linux例如 RLIMIT_STACK )限制在运行时堆栈了。


  

是否可以提高?


有可能取决于实现是可能的。看到你的链接了解详细信息的文档。并可能对操作系统文件和可执行文件格式了。

您应该分配巨大数组一样,动态。

I've tried the below program. The intent by which this program was created is to discover more about stack sizes.

int main()
{
    int nStack[100000000];
    return 0;
}

After executing the above code, the program crashes due to huge stack size allocation. What is the maximum possible size of the stack? Is it fixed for every program/computer? Can it be increased?

I want to know for the sake of knowledge. If anyone can provide examples in C/C++, it would be very helpful.

解决方案

What is the maximum size of the stack?

Depends on implementation. One to few megabytes is typical on PC nowadays.

Is it fixed for every program/computer?

It's typically fixed on linking but standard does not define that it is. Some operating systems can limit the stack during runtime too (RLIMIT_STACK on linux for example).

Can it be increased?

It may be possible depending on implementation. See the documentation of your linker for details. And possibly the documentation for the OS and the executable format too.

You should allocate huge arrays like that dynamically.

这篇关于最大堆栈大小为C / C ++程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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