I am writing a C program that uses lots of recursive functions. I am also using a dynamic list to store some data while recursing. I implemented a Push function to push data into the list.
After several calls for the push function ” > 17,000 times” i am getting the following error:
Unhandled exception at 0x77963c47 in Prob – Cap CE.exe: 0xC00000FD: Stack overflow.
at return HeapAlloc(_crtheap, 0, size ? size : 1); that is called from stack->listNode = malloc(sizeof(struct Node)); in the Push function.
I opened task manager and identified that I still have lots of free memory. So I guess it is not a memory leak issue.
Is there any limitation on how much I can add to the list, or how many times I can call a function?
“>17,000 times” is not “several”. It’s bloody loads.
You can’t expect your stack to hold 17,000 frames (and how much it can hold is implementation-dependent, and also depends on how much data is in each frame).
Use iteration instead.