Is this a stack problem? 
Author Message
 Is this a stack problem?

Hi, I'm working on an assignment, which is creating a parsing algorithm for
some set of grammatical rules.

I was using recursion, and had a couple of local arrays of 80 characters.
My program kept crashing, and then would actually complete it's execution,
and then crash as the program terminated (kinda weird).  I thought maybe
since I was doing recusion that I was possibly overflowing the stack.  I'm
working in DOS4GW with Watcom.

I then changed my function so it dynamically allocated memory for all arrays
(had to throw in some free() statements at key areas in my recursive
function), and my program doesn't crash anymore.

It seems that the stack was the problem, but my question is WHY?  How do I
deal with the stack?  Is there some way to expand it? Or even CHECK for
overflow?  If I have enough memory on my system, shouldn't it just keep
using free memory (or is that not from the heap?).

I was just thinking... Well, what if I didn't declare arrays of 80 bytes,
but I still used a lot of variables, and the recursion ran really deep.  I
could've still overflowed the stack without doing anything too terribly
wrong(like allocating large arrays).

Would it just be the case that if recursion has to run that deep, the
algorithm shouldn't be done recursively??

Thanks for any info.



Fri, 25 Aug 2000 03:00:00 GMT  
 Is this a stack problem?

: Hi, I'm working on an assignment, which is creating a parsing algorithm for
: some set of grammatical rules.

: I was using recursion, and had a couple of local arrays of 80 characters.
: My program kept crashing, and then would actually complete it's execution,
: and then crash as the program terminated (kinda weird).  I thought maybe
: since I was doing recusion that I was possibly overflowing the stack.  I'm
: working in DOS4GW with Watcom.

: I then changed my function so it dynamically allocated memory for all arrays
: (had to throw in some free() statements at key areas in my recursive
: function), and my program doesn't crash anymore.

: It seems that the stack was the problem, but my question is WHY?  How do I
: deal with the stack?  Is there some way to expand it? Or even CHECK for
: overflow?  If I have enough memory on my system, shouldn't it just keep
: using free memory (or is that not from the heap?).

I'm pretty sure that you'll have to look at both the compiler docs,
_and_ the dos extender docs, for the answer to this.  All the compilers
I've seen have way of increasing the stack, and all of them are different.
On some systems no method is needed; the stack increases without bounds.
But the Watcom compiler docs are the place to start.

Will



Fri, 25 Aug 2000 03:00:00 GMT  
 Is this a stack problem?

Quote:

>I'm pretty sure that you'll have to look at both the compiler docs,
>_and_ the dos extender docs, for the answer to this.  All the compilers
>I've seen have way of increasing the stack, and all of them are different.

Well, a _compiler_ should generate code, but never worry about things
like stack size. If it does it is broken or tries to work in a broken
environment.

Quote:
>On some systems no method is needed; the stack increases without bounds.

Guess it would be easiest to install an operating system first.

Wolfgang Denk



The use of Microsoft crippleware systems is a sin that  carries  with
it its own punishment.



Fri, 25 Aug 2000 03:00:00 GMT  
 Is this a stack problem?

|Hi, I'm working on an assignment, which is creating a parsing algorithm for
|some set of grammatical rules.
|
|I was using recursion, and had a couple of local arrays of 80 characters.
|My program kept crashing, and then would actually complete it's execution,
|and then crash as the program terminated (kinda weird).  I thought maybe
|since I was doing recusion that I was possibly overflowing the stack.  I'm
|working in DOS4GW with Watcom.

Recursion typically operates by placing values in a temporary store.  In
many machines this takes the form of a stack.  This stack cannot typically
grow without bounds; it will frequently have a default size.  Sometimes
you can Q&D the problem by changing the stack size (see your
compiler docs).  Otherwise, do as you indicate below

|I then changed my function so it dynamically allocated memory for all
arrays
|(had to throw in some free() statements at key areas in my recursive
|function), and my program doesn't crash anymore.

but be sure that your malloc calls succeed so you can fail neatly.
And yes, it is quite possible that you should rethink whether you
should be using recursion at all.



Fri, 25 Aug 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. I am new to programming and am lost

2. /STACK increase the stack, means decrease the heap ?

3. The C stack (or: implementing a stack trace)

4. /STACK increase the stack, means decrease the heap ?

5. STACKS and STACKS

6. Stack Structure and Stack Overflow for CE

7. I am a retard (perhaps a simple problem??)

8. Macro with functions problem -- why am I stupid?

9. Graphics problem -what am I doing wrong?

10. HELP, I am having problems with pointer...

11. I am having problems setting up that a specified dialog is displayed before any others

12. a very simple problem about # include files but i am a beginer

 

 
Powered by phpBB® Forum Software