Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Alleviate Stack Overflow? 4

Status
Not open for further replies.

Spannerman

Programmer
Dec 31, 2000
26
GB
I am sorting a maximum of 650 items in a table and then reading a sequential file to pull out the relevant data
that goes with the sorted item.Every now and then my system crashes with STACK OVERFLOW!!!

I could not master Q-Sort so I am using the good old BUBBLE SORT which I am very familiar with. Any ideas?????
 
do you use any recursive function?? 650 items can not cause stack overflow

 
recurive means inside the function you call itself..
check your program, maybe you are using but you don't know..
or are you trying to use q-sort in your program??? if there is, check the function because, recursive applied for q-sort

on stdlib.h or search.h qsort function is there, you can go thru the help for the syntax
 
Check FAQ in Pascal forum,
it has more theory on how it is implemented,
code there looks very childish, just one example but the theory will give you an idea how recursion is used. Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
This discussion has gotten off of relieving the overflow and turned into a recursive lesson, which is interesting, but doesen't answer the question.

There's also an faq here on recursion, it's about the most basic example, but gives you the gist of it.

One way to see if it is the size that's giving the overflow is to sort fewer items. why not half the sorting size to see if that helps any, and if not half it again. You may need to do 2 passes at sorting your stuff, if it's a recursive sort, you may need to sort 2 or more chunks of the array, and then merge them into one array again. This is fairly easy to do, but you'll have to write a merge.

If you have 2 sorted lists, a merge is fairly simple, just examine the 2 smallest elements in each list, and take the one that is smallest of the 2 to start the new combined list. Do this until each list is empty, and you've merged 2 sorted lists and kept them in order.

MWB.

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
The recursion lesson here is not irrelevant.
Stack Overflow very often occurs when one uses this kind of functions.When you pass too many parameters and when you have many itterations calling this function, so everything in pushed to the stack.
It this could be the reason of your Stack Overflow. If {I suspect} you have a loop then change number of itteration to smaller number.
Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
Was it nessicary to reapeat what I just said? I'm just wondering...

MWB.

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
try using static variables when possible. When a recursive sort calls itself (especially qsort), it makes too many copies of the variables on the activation record. I recently had to write a modified quicksort algo, and that solved my overflow problems.

-n-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top