Hi,

I have a recursion in my application and very rearly it throws StackOverFlowException, but it happens and I have to solve it somehow. Here's my method:

private double GeneratePHybridValue(DataRow row)
        {
            double p_hybrid_value = 0.0;
            double min_value;
            double max_value;

            double old_M = (double)row["M"];
            double old_G = (double)row["G"];
            double old_H = (double)row["H"];

            min_value = Math.Min(Math.Min((double)row["M"], (double)row["G"]), (double)row["H"]);
            max_value = Math.Max(Math.Max((double)row["M"], (double)row["G"]), (double)row["H"]);

            if ((max_value - min_value) < 0.01)
            {
                p_hybrid_value = (min_value + max_value) / 2.0;

            }
            else
            {
                row["M"] = ArithmeticMean(old_M, old_G, old_H);
                row["G"] = GeometricMean(old_M, old_G, old_H);
                row["H"] = HarmonicMean(old_M, old_G, old_H);
                p_hybrid_value = GeneratePHybridValue(row);

            }

            return p_hybrid_value;

        }

I read few articles and they proposed to increase my stack size like that:
editbin /stack:4000000 NameOfTheExe.exe

I tried but it didn't help mi at all. Any suggestions. Please have in mind that the datatable I work with has 3257 rows and having the recursion for each row of that table! Thank you in advance!

Recommended Answers

All 2 Replies

The outcome of if ((max_value - min_value) < 0.01) depends on the values in your table. If this never becomes true, you iterate forever and will get a stackoverflow.

The outcome of if ((max_value - min_value) < 0.01) depends on the values in your table. If this never becomes true, you iterate forever and will get a stackoverflow.

Yes, but that's condition is the idea of the whole algorithm. I'm calculation a p-value that is between [0.1] and we're searching of a realy small p-value. Maybe I should talk to my supervisor, because this is for my thesis and the algorithm idea is hers :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.