我们有更多的静态变量的内存空间吗? [英] do we have more memory space for static variables?

查看:128
本文介绍了我们有更多的静态变量的内存空间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int dp[2009][2009]

static int dp[2009][2009];

我制作了一个c ++程序,其中我声明一个arry为

int dp [2000] [2000]
程序停止工作,由于非常多的内存分配。当我宣布它为静态

int dp [2009] [2009],程序工作正常。
这是什么原因

I made a c++ program in which i declared an arry as
int dp[2000][2000] the program stopped working due to very much memory allocation .when i declared it as static
int dp[2009][2009] , the program worked fine . whats the reason for this ??

推荐答案

自动存储的变量只能使用一个小的,的空间(堆栈)。相比之下,具有静态存储持续时间的变量可以使用大得多的空间,主要受全局机器约束的限制。

Variables with automatic storage can only use a small, implementation-dependent amount of space ("the stack"). By contrast, variables with static storage duration can use a much larger amount of space, constrained mostly by the global machine constraints.

不幸的是,语言中没有机制告诉你有多少空间可用于自动变量。这是一个实现相关的限制,当你超过它产生未定义的行为,但你不知道什么是限制或你有多少剩下...

Unfortunately, there is no mechanism within the language to tell you how much space is available for automatic variables. It's an implementation-dependent limit that when you overstep it produces undefined behaviour, but you cannot know what the limit is or how much you have left...

这篇关于我们有更多的静态变量的内存空间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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