linux 堆栈大小函数,函数栈的大小(Stack Overflow Problems)

Stack Overflow Problems

This file gives some hints on addressing this problem on different platforms. Under Unix-like systems, programs may throw a "Segmentation Fault"error.  This can be due to stack overflow, especially from recursive function calls or huge data sets.  In our demo program "Pi"(see "$(CORE_PATH)/progs/pi"), we compute Pi to any number of desiredbits or digits.  Here are some test results on when stack overflowswill occur on different platforms, using their default stack sizes.

platform       default size   # bits  # digits

===============================================================

SunOS/Solaris  8192K bytes    <=39875 <=12003 (Shared Version)

Linux         8192K bytes    <=62407 <=18786                            (linux默认8M)

Windows   1024K bytes    <=10581 <=3185  (Release Version)     (windows默认1M)

cygwin      2048K bytes    <=3630  <=1092  (cigwin默认2M)(自己查看的结果为2043K)

If we now change their stack size to their maximum, our Pi program can compute more bits.

How to change the default stack size on different platforms:In general, under Unix-like platforms, the stack size is controlled by environment variable, not the program itself.  (linux下非编译器决定栈大小,而是由操作系统环境决定)So you cannot pass any flags to the compilers, like gcc, to setup stack size.  Under Windows platforms, thestack size information is contained in the executable files.  It can be set during compilation in Visual C++, but this is not available in gcc. (windows下可以由编译器决定栈大小)Alternatively, Microsoft provides a program "editbin.exe" which can change theexecutable files directly.  Here are more details:

stack使用量計算toolは以下です

SunOS/Solaris:

> limit                 # shows the current stack size

> unlimit               # changes the stack size to unlimited

> setenv STACKSIZE 32768 # limits the stack size to 32M bytes

Linux:

> ulimit -a           # shows the current stack size (ulimit为系统命令,非编译器命令)

> ulimit -s 32768      # sets the stack size to 32M bytes

Windows (during compilation):

1. Select "Project->Setting".

2. Select "Link" page.

3. Select "Category" to "Output".

4. Type your preferred stack size in "Reserve:" field under "Stack  allocations". eg, 32768 in decimal or 0x20000 in hexadecimal. Windows (to modify the executable file):

There are two programs included in Microsoft Visual Studio, "dumpbin.exe" and "editbin.exe".  Run "dumpbin /headers executable_file", and you can see the "size of stack reserve" information in "optional header values".  Run "editbin /STACK:size" to change the default stack size

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值