|
The location is random, I even pass the counter to see how many times the function is called. Even then, the number is not always the same. Thy funny thing it was working before, all of a sudden it's not working.
Thank you.
|
|
|
|
|
Well that is the nature of overflow exceptions: they depend on the system state you run in which changes over time (resources like memory comes and goes).
Something else is going on then. Are you getting the exception throw from outside your recursive try/catch block? That means the problem is elswhere (or everywhere). Or more specificially, the try/catch block doesn't fail because it can allocate 99% of the thread's stack space but then something else goes off and does something that requires 2% more.
If this is the case you need either need to place the try/catch block "higher" or rethink your design. I would encourage you to rethink your design since terminating your recursion because you ran out of stack is somewhat abnormal and worst not reproducable.
|
|
|
|
|
Thank you for your input. I will try to rethink some of the steps within the function. Unfortunately, when you are trying to calculate IRR (rate of return), and the function throws an exception (like stack overflow), it does not mean that there is no calculated rate, it's just did not get to the point where it can return the calculated value. I run this function on the array of numbers, which sum reaches into hundreds of millions, and when you trying to calculate the rate of return it sometimes takes 30 iterations, or 100 etc.. That's why I can't really bind myself with iteration limit. Well, I will have to come up with something. Thank you guys anyway it was a great help.
|
|
|
|
|
Have you considered rewritting this using a while loop?
<br />
while (!ExitCondition)<br />
{<br />
}<br />
You should be able to rewrite your recursion into a while loop which wouldn't require an iteration limit at all. It will probably be a little more complicated, but it will avoid your memory problems.
Recursion is good for some (small) problems but you have to be aware that the memory usage can baloon dramatically.
|
|
|
|
|
You simply cannot catch StackOverflowExceptions. When the stack is full, the runtime cannot allocate space for the catch handler, so it won't be run.
If you really need to code like this, create some variable that counts the stack depth and throw a custom exception before the stack if full.
|
|
|
|
|
Do I have to create a stack variable as well?
Something like : Stack myStack = new Stack();
But that means I have to place every output on top of this stack.
If not, what do you mean by counting the depth of the stack?
Thank you.
|
|
|
|
|
Well there are ways in the Diagnostic namespace to look at the stack but I wouldn't recommend doing this at all. As stated by many others, the ability of the CLR to allocate object references depends on the machine's state which is constantly changing.
Beyond that you should heed my warning about inferring extra information in any exception. It would be like inferring that a IOException means a file is bad.
You seriously need to rethink how to calculate rate of return. I wouldn't have done recursion in the first place. Iteration might be a long calculation but at least it is reliable. Your method now will randomly stop and worst report bogus data.
|
|
|
|
|
As Daniel said, you cant catch it. Create a counter and see how deep you are going. Then rethink your algorhitm.
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
You can't catch StackOverflowException.
My suggestions:
1. It can be proved that any tail-recursive call can be reduced to a simple "while" loop. It seems to be your case "return calcIRR (..."
2. You're passing a lot of big parameters. Why not passing a reference to a class that contains all this information? This would reduce your stack size.
3. Do you have lots of local variables? If yes, try extracting methods from your code, so your stack size becomes smaller.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
Can anyone help me out with this.
How do I retrieve a specific Environment(User Variables/System Variables) using C# without iterating through the ManagementObjectSearcher Collection.
Is there a way I can get it using System.Environment.GetEnvironmentVariable(s), I tried this but it did not work.
Thank you,
S. Balakrishnan
|
|
|
|
|
In 1.1 there is a class SystemInformation that might provide the information your looking for.
|
|
|
|
|
Why doesn't it work? What environment variable are you querying for?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
System.Environment.GetEnvironmentVariable()
Matt Gerrans
|
|
|
|
|
Hi,
I've an existing file in a isolated storage and i want to rename it with another name.
how can i do that ?
Thanks !
|
|
|
|
|
if(IO.File.Exists(oldpath))
{
IO.File.Move(oldpath, newpath);
}
else
{
Throw new FileNotFoundException;
}
|
|
|
|
|
To do this, i need to have the path of my file in a isolated Storage.
How can i have it ?
Thanks
|
|
|
|
|
Use UNC: \\servername\path
|
|
|
|
|
There is a Msg.dll file which is built by VC6.0.
I want to use the event OnComm() in it.
How to define it ?
Thanks!
|
|
|
|
|
You need to give more information. Is the "event" an OCX event? Or is a custom event that only the shared object can understand? Or is it something else entirely (like a virtual or a callback)?
|
|
|
|
|
afx_msg LONG OnCommunication(WPARAM, LPARAM);
|
|
|
|
|
Hi all,
I want to create a Richtext Editor which should be of A4 size
The content should not exceed more than A4 size.
The problem that i am facing now is when i enter text and press
the enter key the richtextbox gets the scrollbar and accepts the text.
i want to block this, i dont want the richtext to have the scroll and
it should not accept the text when the last line is reached
Please if anyone could help me
it's very urgent!!!!!!!!!!!!!!!!
Thanks and Regards,
Pramod Yadav
|
|
|
|
|
Hello,
I call a method GetCustomers() in a webservice, by clicking on a button in the related Windows application. It fetches the data from the Northwind database (Customers table), and shows it in a DataGrid in the Form (via a DataSet)
dataGrid1.DataSource = myDS; //myDS id the DataSet
//dataGrid1.SetDataBinding(myDS, "Customers");
I would just like to know why the SetBinding method doesn´t work with the client application. However if I click on "Invoke" from the Testing webservice in the browser (am using VisualStudio 2003),
the SetDataBinding method does work.
Why ?
Thanks a lot.
|
|
|
|
|
Hi,
Is there o property for a combobox, so that this control is not editable (so that you can't type text in it).
Thanks!
|
|
|
|
|
|
hello everybody,
my name is Wolfgang Mergenthaler in Flörshei/Germany. I keep having this problem over and over: My program runs nicely, except if I click the title bar in the main form. Then the following happens: The program stalls, I get the message "Keine Rückmeldung" (No response).
What can I do ?
Thanks a lot for help !
Wolfgang
|
|
|
|