How to change the default stack size on different platforms

川长思鸟来 2022-08-04 04:21 183阅读 0赞
  1. Stack Overflow Problems
  2. =======================
  3. This file gives some hints on addressing this problem on different platforms.
  4. Under Unix-like systems, programs may throw a "Segmentation Fault"
  5. error. This can be due to stack overflow, especially from recursive
  6. function calls or huge data sets. In our demo program "Pi"
  7. (see "$(CORE_PATH)/progs/pi"), we compute Pi to any number of desired
  8. bits or digits. Here are some test results on when stack overflows
  9. will occur on different platforms, using their default stack sizes.
  10. platform default size # bits # digits
  11. ===============================================================
  12. SunOS/Solaris 8172K bytes <=39875 <=12003 (Shared Version)
  13. Linux 8172K bytes <=62407 <=18786
  14. Windows 1024K bytes <=10581 <=3185 (Release Version)
  15. cygwin 2048K bytes <=3630 <=1092
  16. If we now change their stack size to their maximum, our Pi program can
  17. compute more bits.
  18. platform stack size # bits # digits
  19. ===============================================================
  20. SunOS/Solaris unlimited >=100,000 30102
  21. Linux 8172K bytes <=33,219,282 <=10,000,000(?)
  22. Windows 32768K bytes <=343077 <=12041
  23. How to change the default stack size on different platforms:
  24. In general, under Unix-like platforms, the stack size is controlled
  25. by environment variable, not the program itself.
  26. So you cannot pass any flags to the
  27. compilers, like gcc, to setup stack size. Under Windows platforms, the
  28. stack size information is contained in the executable files. It can be set
  29. during compilation in Visual C++, but this is not available in gcc.
  30. Alternatively, Microsoft provides a program "editbin.exe" which can change the
  31. executable files directly. Here are more details:
  32. SunOS/Solaris:
  33. ==============
  34. > limit # shows the current stack size
  35. > unlimit # changes the stack size to unlimited
  36. > setenv STACKSIZE 32768 # limits the stack size to 32M bytes
  37. Linux:
  38. ======
  39. > ulimit -a # shows the current stack size
  40. > ulimit -s 32768 # sets the stack size to 32M bytes
  41. Windows (during compilation):
  42. =============================
  43. 1. Select "Project->Setting".
  44. 2. Select "Link" page.
  45. 3. Select "Category" to "Output".
  46. 4. Type your preferred stack size in "Reserve:" field under "Stack
  47. allocations". eg, 32768 in decimal or 0x20000 in hexadecimal.
  48. Windows (to modify the executable file):
  49. =======================================
  50. There are two programs included in Microsoft Visual Studio, "dumpbin.exe"
  51. and "editbin.exe". Run "dumpbin /headers executable_file", and you can see
  52. the "size of stack reserve" information in "optional header values". Run
  53. "editbin /STACK:size" to change the default stack size.
  54. from http://www.cs.nyu.edu/exact/core/doc/stackOverflow.txt

发表评论

表情:
评论列表 (有 0 条评论,183人围观)

还没有评论,来说两句吧...

相关阅读