473,385 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Stackoverflow Exception


Hello,

Iam quite new to programming and dont know enough about the stack.
My problem is if I call a recurcive function like in the code
TestCalc(100000),
I get at some integer argument size a stack overflow exception.
The recursion is not endless. But at 1000000 the exception is thrown.
What is limitation of the stack or how can I figure it out.
Are there restrictions about function calls?

Thanks for your answer..
:-)

Code Part:

private void TestCalc(int counter)
{
if (counter <= 0)
{
return;
}

TestCalc(counter - 1);
}

void BtnTestStart_Click(object sender, EventArgs e)
{
TestCalc(100000);
}
May 5 '06 #1
2 1693
I believe that the stack is 2 MB by default. Each call stored a 4 byte
return address on the stack (and perhaps 4 more bytes for storing the
previous stack frame). That gives you no more than 500000 recursive calls.

If your code even comes near that number of calls, you should take a
step back and consider where the code design went wrong.

wansch wrote:
Hello,

Iam quite new to programming and dont know enough about the stack.
My problem is if I call a recurcive function like in the code
TestCalc(100000),
I get at some integer argument size a stack overflow exception.
The recursion is not endless. But at 1000000 the exception is thrown.
What is limitation of the stack or how can I figure it out.
Are there restrictions about function calls?

Thanks for your answer..
:-)

Code Part:

private void TestCalc(int counter)
{
if (counter <= 0)
{
return;
}

TestCalc(counter - 1);
}

void BtnTestStart_Click(object sender, EventArgs e)
{
TestCalc(100000);
}

May 5 '06 #2
The default stack size is 1 Mb ... You can actually change it on a per
thread basis in 2.0 easily
http://geekswithblogs.net/gyoung/arc.../02/76961.aspx for win
XP/2003 (although most people change it down not up:)). The amount of stack
used per recursion actually depends on how many parameters/variables the
method has as the stack is where these arew stored.

btw Goran is on the money with wonderring what went wrong with design :)

Cheers,

Greg

"Göran Andersson" <gu***@guffa.com> wrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
I believe that the stack is 2 MB by default. Each call stored a 4 byte
return address on the stack (and perhaps 4 more bytes for storing the
previous stack frame). That gives you no more than 500000 recursive calls.

If your code even comes near that number of calls, you should take a step
back and consider where the code design went wrong.

wansch wrote:
Hello,

Iam quite new to programming and dont know enough about the stack.
My problem is if I call a recurcive function like in the code
TestCalc(100000),
I get at some integer argument size a stack overflow exception.
The recursion is not endless. But at 1000000 the exception is thrown.
What is limitation of the stack or how can I figure it out.
Are there restrictions about function calls?
Thanks for your answer.. :-)

Code Part:

private void TestCalc(int counter)
{
if (counter <= 0)
{
return;
}

TestCalc(counter - 1);
}

void BtnTestStart_Click(object sender, EventArgs e)
{
TestCalc(100000);
}

May 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Babu Mannaravalappil | last post by:
Can somebody please help me figure out why the following method exceptions out? Execution at the line marked with ********** hangs for about 15 seconds and then I get an error that says an...
1
by: TDOR | last post by:
I have started a nt service project in VS2003, added a timer from the toolbox, and set the timer to trigger every 20 secs. The method that the timer calls has among others these lines: ...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
6
by: sjoerd van den Nieuwenhof | last post by:
hello, i'm getting a error named: an unhandled exception of type 'system.stackoverflowException' occured in unknow module. whta does this mean?? please help me
23
by: Rob Meade | last post by:
Hi all, I think I may have created a bit of a problem earlier with some of my classes.... I *think* that I may have inherited a class that was inheriting that class - endless loop kinda...
5
by: Gene Ariani | last post by:
Is there a limit to how big a rowfilter on dataview could be? my rowfilter is dynamically generated and if its get too big I get a stackoverflow error other wise it works fine. Any direction is...
1
by: Analizer1 | last post by:
Is there a real time debugger , out here for xsl transform when i run the xsl transform with a xml file (that represents 2000 or more rows from a sql 2005 tables) I get a Statckoverflow...
0
by: mmayur | last post by:
I'm using ANTLR parser for a txt file of around 5 MB. My main grammer module contains displaying contents between START_TAG(<) and END_TAG(>). fragment ELEMENT : ( (ELEMENT ...
2
by: Wan | last post by:
Dear Group, I have a small application with two buttons and three textboxes with databinding. One of the textboxes has a ˇ§textchangedˇ¨ event and other 2 textboxes are attached with the same...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.