increase stack size in VC++ 2002
-
I am running a program that manipulates images using int arrays as a substitute for the images. Well I can't create another one because it causes a stack overflow error. If I make it 200x100, I have enough space. If I make it 200x200, it goes over. I have read that you can increase the stack size using /F 1024000 but that doesn't seem to work. Any ideas? Right now I have converted all the arrays to short instead of int as a workaround but that seems silly on a machine with 512MB of RAM.
don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker
-
don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker
I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.
-
I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.
short* temparray = new short[PICTUREARRAYHEIGHT * PICTUREARRAYWIDTH];
temparray[y * PICTUREARRAYWIDTH + x] = value;is a simple solution. No need to allocate an array of arrays, which you'd have to do if you had wanted to access the pixels in "2d"-fashion.
-
I am running a program that manipulates images using int arrays as a substitute for the images. Well I can't create another one because it causes a stack overflow error. If I make it 200x100, I have enough space. If I make it 200x200, it goes over. I have read that you can increase the stack size using /F 1024000 but that doesn't seem to work. Any ideas? Right now I have converted all the arrays to short instead of int as a workaround but that seems silly on a machine with 512MB of RAM.
Forget using
malloc
andfree
or evennew
anddelete
. Do it using astd::vector
. e.g.// So we can access "std::vector". #include <vector> // We want a vector of ints. typedef std::vector<int> t_IntVec; // Now use the vector in a similar way you'd use the dynamically allocated array. t_IntVec ints(200*200); ints[1*200 + 5] = 1;
Steve -
Forget using
malloc
andfree
or evennew
anddelete
. Do it using astd::vector
. e.g.// So we can access "std::vector". #include <vector> // We want a vector of ints. typedef std::vector<int> t_IntVec; // Now use the vector in a similar way you'd use the dynamically allocated array. t_IntVec ints(200*200); ints[1*200 + 5] = 1;
Steve -
I'll try that tomorrow when I get back into work. Isn't there ANY way to just increase the size of the stack so I can use plain old 2-d arrays?
-
don't allocate them on the stack. that's why jesus invented malloc and new. Cleek | Image Toolkits | Thumbnail maker
-
I am not sure I am doing this right. This is what my code looks like now: short temparray[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; I am trying to use new short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH]; but that gets an error message saying that it can't convert type short (*) to short [][320] I can't find any examples of malloc being used with arrays.
sleze wrote:
short * temparray = new short[PICTUREARRAYHEIGHT][PICTUREARRAYWIDTH];
You can't create 2D arrays like this using
new
. Try this insteadshort **temparray = new short*[PICTUREARRAYHEIGHT];
for (int i=0;i<PICTUREARRAYHEIGHT;i++)
temparray[i] = new short[PICTUREARRAYWIDTH];You would also have to delete using a similar method to prevent leaks.
-
-
That solved the normal stack overflow error. But now I have a new one. When I try to move the window once image processing is going on, the program crashes with a stack overflow error. Increasing the stack to 10MB doesn't seem to fix it. Any ideas?
I was reluctant to tell you about the
/STACK
switch because I had doubts that it would fix your problem - most times "the quick fix" causes more problems then it solves. 200x200 integers is just 200x200x4=[EDIT]160KB[/EDIT]. It seems unlikely that the size of the array was actually the cause of the problem. I suspect the problem is that you're recursing too deeply. Can you send a stack trace when you get the crash? Steve -- modified at 8:55 Saturday 22nd April, 2006 -
I was reluctant to tell you about the
/STACK
switch because I had doubts that it would fix your problem - most times "the quick fix" causes more problems then it solves. 200x200 integers is just 200x200x4=[EDIT]160KB[/EDIT]. It seems unlikely that the size of the array was actually the cause of the problem. I suspect the problem is that you're recursing too deeply. Can you send a stack trace when you get the crash? Steve -- modified at 8:55 Saturday 22nd April, 2006Isn't 200x200x4 = 160K?
-
Isn't 200x200x4 = 160K?
Oops - you're right. That is a lot to have on the stack. Steve