Nevron Gauge for SharePoint
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » recursion with StackOverflowException
       
Author Reply
Helber Galarga
posted 2 posts
since Aug 25, 2010 
from

recursion with StackOverflowException

  Posted on: 30 Aug 2010       
Hi

I am new in this forum, and have some trouble regarding StackOverflowException

suposse I would want to control StackOverflowException originated by calling a recursive method,  that gets the call stack over it's defaults capabilites.

-in my case for my homework this 'd be a call to Ackermann(3,10)- . And... Knowing that is not possible to control StackOverflowException since C# 2.0...

Since I don't know if it is possible in C# to modify memory propierties of the call stack, the only solution left -if it isn't posibly to grow bigger the call stack- would be control thru reading the call stack state, before it overflows...

I 've been told that using threads -tru delegates- and editing its memory properties can help in this case, but... I'm having problems trying this...

 namespace Ackermann
{
class AckermannREC
{


public static long Ackermann(long m, long n)
{
if (m > 0)
{
if (n > 0)
return Ackermann(m - 1, Ackermann(m, n - 1));
else if (n == 0)
return Ackermann(m - 1, 1);
}
else if (m == 0)
{
if (n >= 0)
return n + 1;
}
throw new System.ArgumentOutOfRangeException();
}


static void Main()
{
long m = 3, n = 9;

Console.WriteLine("Ackermann({0}, {1}) = {2}", m, n, Ackermann(m, n));
Console.ReadKey();
}


}
}



Any help or suggestion would be appreciated...
Bernhard Hiller
posted  2 posts
since  Apr 16, 2008 
from 

 Re: recursion with StackOverflowException
  Posted on: 31 Aug 2010   Accepted Answer     0  
May impression is that many values are calculated over and over again. I would suggest to start with m=0, n=0, store the calculated value and then run two "for" loops for m and n upto their final values, using the previously calculated and stored results.
Helber Galarga
posted  2 posts
since  Aug 25, 2010 
from 

 Re: recursion with StackOverflowException
  Posted on: 01 Sep 2010        0  
Now i'm late doing my homework, i realized what i really was asked for was using some library bundled in .NET (diagnostics, threads, or some so... in order to anticipy to the StackOverflowexception thrown by the compiler),

 Because it is given in the problem im trying to solve, you can`t touch any line of the recursive code... so the idea behind the homework is to use some library  -for example StackTRace, StackFrame, or the properties of the threads like stack size - and act before the compiler, i.e print a message and pause the execution just before the compiler throws the StackOverflowException (my idea is to pause the program based on the call stack information before

any help or suggestion would be welcomed...
       
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved