stack-overflow

StackOverflowError computing factorial of a BigInteger?

丶灬走出姿态 提交于 2019-11-26 16:59:51
问题 I am trying to write a Java program to calculate factorial of a large number. It seems BigInteger is not able to hold such a large number. The below is the (straightforward) code I wrote. public static BigInteger getFactorial(BigInteger num) { if (num.intValue() == 0) return BigInteger.valueOf(1); if (num.intValue() == 1) return BigInteger.valueOf(1); return num.multiply(getFactorial(num.subtract(BigInteger.valueOf(1)))); } The maximum number the above program handles in 5022, after that the

What is a stack overflow?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 16:31:27
问题 What is a stack overflow error? What type of programs/programming languages is it likely to occur in? Is it unlikely to occur in web application code? 回答1: From Wikipedia: In software, a stack overflow occurs when too much memory is used on the call stack. In many programming languages, the call stack contains a limited amount of memory, usually determined at the start of the program. The stack is a data structure that keeps record of the point the subroutines of a program should return

ES6 Tail Recursion Optimisation Stack Overflow

折月煮酒 提交于 2019-11-26 16:12:36
问题 Having read Dr Rauschmayer's description of recursive tail call optimisation in es6, I've since been trying to recreate the 'zero-stack' execution of the recursive factorial function he details. Using the Chrome debugger to step between stack frames, I'm seeing that the tail optimisation is not occurring and a stack frame is being created for each recursion. I've also tried to test the optimisation by calling the function without the debugger, but instead passing 100000 to the factorial

How do I increase the stack size for Apache running under Windows 7?

坚强是说给别人听的谎言 提交于 2019-11-26 15:38:37
问题 I think I am getting stack overflows running a cakePHP application on an Apache server under Windows 7. 回答1: This problem happens more often on Windows platform, because of smaller Apache's default stack size. There is 1 MB default stack size on Windows, unlike 8 MB on Unix/Linux platforms. It could be a reason, why some for example PHP scripts works properly on Linux, but cause crash of Apache on Windows. Furthermore, the crash is silent ( segmentation fault ), there is no error message,

How to change stack size for a .NET program?

社会主义新天地 提交于 2019-11-26 15:24:53
I have a program that does recursive calls for 2 billion times and the stack overflow. I make changes, and then it still need 40K recursive calls. So I need probably several MB stack memory. I heard the stack size is default to 1MB. I tried search online. Some one said to go properties ->linker .........in visual studio, but I cannot find it. Does anybody knows how to increase it? Also I am wondering if I can set it somewhere in my C# program? P.S. I am using 32-bit winXP and 64bit win7. The easiest way to set the stack size from .NET 2.0 and Win XP onwards is to spawn a new thread with the

Large 2D array gives segmentation fault

和自甴很熟 提交于 2019-11-26 15:21:09
问题 I am writing some C++ code in Linux where I have declared a few 2D arrays like so: double x[5000][500], y[5000][500], z[5000][500]; During compilation there is no error. When I execute it says "segmentation fault". Wen I reduce the size of the array from 5000 to 50, the program runs fine. How can I protect myself against this problem? 回答1: If your program looks like this ... int main(int, char **) { double x[5000][500],y[5000][500],z[5000][500]; // ... return 0; } ... then you are overflowing

runtime error (stack overflow)

我的未来我决定 提交于 2019-11-26 14:54:56
问题 I've got this code in C language: char *options[100000]; int k[100000]; char *param[100000]; int n; int i,j; ... scanf("%d",&n); for (i=0;i<n;i++) { scanf("%s%d",&options[i],&k[i]); param[i]="On"; } ... just as the programm reaches this point: scanf("%s%d",&options[i],&k[i]); I get the runtime error (stack overflow). The input here should be like this: word1 number1 word2 number2 and so on. I've got no idea why is this happening. What's the problem? 回答1: Ok... so I thought someone would

Nested JSF Composite Components leading to a Stack Overflow exception

那年仲夏 提交于 2019-11-26 14:45:53
问题 The problem When I attempt to nest a Composite Component within itself, with some logic to end the infinite recursion I receive a stack overflow exception. My understanding is that <c:xxx> tags run at view build time so I was not expecting to have an infinite view build as I presume has been the case. This is the composite component simpleNestable.xhtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http:/

java.lang.StackOverflowError while using a RegEx to Parse big strings

╄→尐↘猪︶ㄣ 提交于 2019-11-26 14:37:13
This is my Regex ((?:(?:'[^']*')|[^;])*)[;] It tokenizes a string on semicolons. For example, Hello world; I am having a problem; using regex; Result is three strings Hello world I am having a problem using regex But when I use a large input string I get this error Exception in thread "main" java.lang.StackOverflowError at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168) at java.util.regex.Pattern$Loop.match(Pattern.java:4295) at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) at java.util.regex.Pattern

What causes a java.lang.StackOverflowError

佐手、 提交于 2019-11-26 14:28:10
What can cause a java.lang.StackOverflowError ? The stack printout that I get is not very deep at all (only 5 methods). Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is public static void main(String... args) { Main main = new Main(); main.testMethod(1); } public void testMethod(int i) { testMethod(i); System.out.println(i); } Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod is called. One of the (optional) arguments to the JVM is the stack size. It's -Xss. I don't know what the