stack-overflow

When does StackOverflowError occur? [duplicate]

痞子三分冷 提交于 2019-11-30 09:12:24
问题 This question already has answers here : What is the maximum depth of the java call stack? (4 answers) Closed 5 years ago . According to Oracle, a StackOverflowError is: Thrown when a stack overflow occurs because an application recurses too deeply. I know what recursion is and normally recursive functions, if not terminated properly, lead to StackOverflowError. To check the number of recursive calls that happen before StackOverflowError is thrown, I wrote this code: package ErrorCases;

Is there any way to determine the available stack space at run time?

↘锁芯ラ 提交于 2019-11-30 09:09:30
I know that stack size is fixed. So we can not store large objects on stack and we shift to dynamic allocations (e.g. malloc). Also, stack gets used when there is nesting of function calls so we avoid recursive functions as well for this reason. Is there any way at runtime to determine how much stack memory is used so far and how much is left ? Here, I am assuming linux environment (gcc compiler) with x86 architecture. Just read %esp, and remember its value goes down. You already know your defaulted max size from the environment, as well as your threads' starting point. gcc has great assembly

Maven compilation: Failure executing javac

和自甴很熟 提交于 2019-11-30 08:15:06
问题 Here is an exception we get when trying to compile a freshly checked out code under Windows Server 2003 with Maven 2.2.1 and JDK 1.6.0_23. Several machines running Ubuntu with the same Maven and JDK version have no problems at all compiling the exact same source. Have tried providing alternative Maven options (i.e. MAVEN_OPTS=-Xms256m -Xmx1024m) to no avail. What could be the cause of this problem and what would be a possible solution? Thanx. [INFO] Compilation failure Failure executing javac

How to predict the maximum call depth of a recursive method?

南楼画角 提交于 2019-11-30 06:17:28
问题 For the purposes of estimating the maximum call depth a recursive method may achieve with a given amount of memory, what is the (approximate) formula for calculating the memory used before a stack overflow error is likely to occur? Edit: Many have responded with "it depends", which is reasonable, so let's remove some of the variables by using a trivial but concrete example: public static int sumOneToN(int n) { return n < 2 ? 1 : n + sumOneToN(n - 1); } It is easy to show that running this in

How to ignore property of property in AutoMapper mapping?

天涯浪子 提交于 2019-11-30 05:58:10
问题 Image a Person and a Group class with a many-to-many relationship. A person has a list of groups and a group has a list of people. When mapping Person to PersonDTO I have a stack overflow exception because AutoMapper can't handle the Person > Groups > Members > Groups > Members >... So here's the example code: public class Person { public string Name { get; set; } public List<Group> Groups { get; set; } } public class Group { public string Name { get; set; } public List<Person> Members { get;

Stack overflow error in C# - but how to fix it?

▼魔方 西西 提交于 2019-11-30 05:34:07
问题 I've run into a really interesting runtime bug which generates a rogue stack overflow. I've defined a structure as follows: public enum EnumDataType { Raspberry, Orange, Pear, Apple }; public class DataRequest { public long DataSize { get { return 0; } set { DataSize = value; } } public EnumDataType DataType { get { return EnumDataType.Apple; } set { DataType = value; } } } The following lines work perfectly: DataRequest request = new DataRequest(); request.DataSize = 60; However, when I step

Stack overflow in Fortran 90

丶灬走出姿态 提交于 2019-11-30 05:30:26
I have written a fairly large program in Fortran 90. It has been working beautifully for quite a while, but today I tried to step it up a notch and increase the problem size (it is a research non-standard FE-solver, if that helps anyone...) Now I get the "stack overflow" error message and naturally the program terminates without giving me anything useful to work with. The program starts with setting up all relevant arrays and matrices, and after that is done it prints a few lines of stats regarding this to a log-file. Even with my new, larger problem, this works fine (albeit a little slow),

Flood fill recursive algorithm

江枫思渺然 提交于 2019-11-30 04:31:36
问题 I'm trying to make an algorithm that could fill an int array in c#. Basically, as the fill tool in MS Paint, I have a color and if I choose (x,y) coordinates in the array, it replaces all the neighbours with the same initial color with the new color. Ex : [0,0,0] [0,1,0] [1,1,0] If I put 3 in (0,0), the array becomes : [3,3,3] [3,1,3] [1,1,3] So I tried it in recursive and it does work, but not all the time. Actually, I have sometimes a "Stack Overflow" error (seems appropriate). Here's my

Achieving Stackless recursion in Java 8

爷,独闯天下 提交于 2019-11-29 21:38:48
How do I achieve stackless recursion in Java? The word that seems to come up the most is "trampolining", and I have no clue what that means. Could someone IN DETAIL explain how to achieve stackless recursion in Java? Also, what is "trampolining"? If you cannot provide either of those, could you please point me in the right direction (i.e., a book to read about it or some tutorial that teaches all of these concepts)? sdgfsdh A trampoline is a pattern for turning stack-based recursion into an equivalent loop. Since loops don't add stack frames, this can be thought of as a form of stackless

Confusing output from infinite recursion within try-catch

。_饼干妹妹 提交于 2019-11-29 21:14:35
Consider the following code. public class Action { private static int i=1; public static void main(String[] args) { try{ System.out.println(i); i++; main(args); }catch (StackOverflowError e){ System.out.println(i); i++; main(args); } } } I am getting i value up to 4338 correctly. After catching the StackOverflowError output getting wired as follows. 4336 4337 4338 // up to this point out put can understand 433943394339 // 4339 repeating thrice 434043404340 4341 434243424342 434343434343 4344 4345 434643464346 434743474347 4348 434943494349 435043504350 Consider Live demo here. It is working