栈内存定义大小有什么需要注意的?

孙建飞的博客 2016-12-22 01:26:51
栈内存一般定义多大合适,最常见的定义大小128,256,及1024是怎么来的,在那种情况下可能会造成定义过大会导致程序崩溃?
...全文
353 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-12-22
  • 打赏
  • 举报
回复
/STACK (Stack Allocations) Home | Overview | How Do I | Linker Options The Stack Allocations (/STACK:reserve[,commit]) option sets the size of the stack in bytes. To find this option in the development environment, click Settings on the Project menu. Then click the Link tab, and click Output in the Category box. The Reserve text box (or in the reserve argument on the command line) specifies the total stack allocation in virtual memory. The default stack size is 1 MB. The linker rounds up the specified value to the nearest 4 bytes. The optional value specified in the Commit text box (or in the commit argument on the command line) is subject to interpretation by the operating system. In Windows NT, it specifies the amount of physical memory to allocate at a time. Committed virtual memory causes space to be reserved in the paging file. A higher commit value saves time when the application needs more stack space, but increases the memory requirements and possibly the startup time. Specify the reserve and commit values in decimal or C-language notation. Another way to set the size of the stack is with the STACKSIZE statement in a module-definition (.DEF) file. STACKSIZE overrides the Stack Allocations (/STACK) option if both are specified. You can change the stack after the .EXE file is built by using the EDITBIN tool.
小灸舞 版主 2016-12-22
  • 打赏
  • 举报
回复
栈大小一般只有几M(1~10M)
http://blog.csdn.net/xxxxxx91116/article/details/10068555
ck2333 2016-12-22
  • 打赏
  • 举报
回复
太大的变量无法在栈中分配(比如说你分配一个大小为10000000的int型数组),这时候就需要从内存中分配空间给变量,否则会造成程序崩溃。
自信男孩 2016-12-22
  • 打赏
  • 举报
回复
程序运行的栈空间没有那么大,它是反复使用的段内存空间,因为函数,局部变量,代码都会用到栈上的空间.空间小,内容也不少,所以,平时定义栈上的数据(比如局部变量数组)时应根据需要来定义大小;如果实在需要比较大空间,建议使用堆上空间,相对栈还是比较大的.或者定义成全局的变量,但是一般对于大数句还是在堆上申请比较好.

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧