是否有堆栈存储器的限制? [英] Is there any limit on stack memory?

查看:126
本文介绍了是否有堆栈存储器的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历一个线程。
程序崩溃,因为
它曾宣布一个函数内部的10 ^ 6阵列本地。

I was going through one of the threads. A program crashed because it had declared an array of 10^6 locally inside a function.

报错的原因是内存分配失败堆栈导致崩溃。

Reason being given was memory allocation failure on stack leads to crash.

在同一阵列全局声明,它的工作好。(在堆内存保存它)。

when same array was declared globally, it worked well.(memory on heap saved it).

现在的时刻,让我们假设,
堆栈增长向下和向上堆

Now for the moment, let us suppose, stack grows downward and heap upwards.

我们有:

现在,我认为,如果出现故障的分配堆栈,
它必须对失败也堆

Now , I believe that if there is failure in allocation on stack, it must fail on heap too.

所以我的问题是:是否有对堆栈大小的限制?
(穿越限制造成程序崩溃)。
还是我失去了一些东西?

So my question is: is there any limit on stack size? (crossing the limit caused the program to crash). Or am I missing something?

推荐答案

这一切都取决于你用​​什么语言和编译器。但是,编译比如C或C ++编写的程序在程序启动时分配一个固定大小的堆栈。通常可以在编译时指定的堆栈的大小(在我的特定的编译器就默认为1 MB)。

This all depends on what language and compiler you use. But programs compiled with for instance C or C++ allocate a fixed size stack at program startup. The size of the stack can usually be specified at compile time (on my particular compiler it default to 1 MB).

这篇关于是否有堆栈存储器的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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