I have the following code for "blob filling" in a bmp. However, it runs out of memory on the stack at loop 7201 or some such. How do I increase memory? I've heard the stack size is 1MB which is WAY TOO SMALL! I have 32GB Ram and I would like to use it to its fullest. Recursion just seems like the way to go on an algorithm like this, if only my stack wasn't too puny. (It's a four way recursion; every function call generates four of the same function calls)
public HashSet<int> evalpxls = new HashSet<int>();
public String addLikePixels(int r, int c, Byte A, Byte R, Byte G, Byte B, Bitmap bmp)
{
reclvl++;
dl("Try r:" + r+ " c:" + c + " reclvl:"+reclvl);
if (evalpxls.Contains(hash(r,c)) || r>=bmp.Height || c>=bmp.Width || r<0 || c<0) return "";
evalpxls.Add(hash(r, c));
var p = bmp.GetPixel(c, r);
String curpix = "[" + r + "," + c +"]";
if (p.A == A && p.B == B && p.G == G && p.R == R) //if same color as main color
{
return curpix + addLikePixels(r + 1, c, A, R, G, B, bmp) + addLikePixels(r, c + 1, A, R, G, B, bmp) + addLikePixels(r - 1, c, A, R, G, B, bmp) + addLikePixels(r, c - 1, A, R, G, B, bmp);
}
else //if different color
return "";
}