Discussion Locked

stack limit in turbo c

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can anybody help me in increasing the stack limit in turbo C being used in recurrsion????
My program requires to have a high number of recurrsions but right now the program is exiting abruptly after doing some recurrsions(may be stack limit is reached after which program exits)

9 replies

by peter ritchie

There should be an option in the IDE to set the stack size. I work with MSVC, so I'm not sure where that would be in Turbo C.

In a pinch you could also add the following line to your DEF file:
STACKSIZE 10240
that sets the size of the stack to10240 bytes. You could change 10240 to be anything you want.

by simonas razminas

Stack limit? Check out $M directive. For stack we have only one segment. Very strange if you got problem with memory. If we have 64kb and function takes about 16 bytes.. so there may be 4096 times deep. Anyway.. everything you can change with options.

by solrak29

Generaly, a recursive function running wild will cause a stack overflow, and in your case your claiming that your function requires so much recursion that you overflow the default stack size setup by turbo c. The default size is usually acceptable,and most compilers have an option in setting this size, but I wonder what version of turbo C you are using? I would also wonder if you considered other methods in your design of the program than using such and expensive call...sounds like you have something that is inefficient in speed and space. But pretty sure there is an option to increase the stack size in your compiler..either command line or IDE.

by solrak29

ok, since I didn't get any answers like, what version of tc your using...I'll tell you this...

According to tc folks the stack size for a program is set at run time and defaults to 4k. This stack size is set by a global variable called _stklen.To change this value you just set it in your program as a global variable...not in a function, not in main...out side...like this:
--snip--
extern unsigned _stklen = 1000000000;

main()....
--snip--

by dinesh.dhamija

Although i personally did not try it....but one of my friend did...& he says that it looks good.... Thanks for the answer....

This discussion is closed to new replies.