Board index » delphi » Error 202 Stack Overflow

Error 202 Stack Overflow

I am writing a program for cruise reservations, using a two dimensional
array for cabin assignments and passenger names, inside a file of
records. When I run it, I get a Stack Overflow error at the beginning of
each procedure. The program compiles with no problem.

The Help screen suggests {$M ...}, but I don't know how to use such a
command. I tried putting it before the Program ...; line as follows:

{$M 65536,0,655360}

but it didn't change anything I could see.

The Help screen also suggests the problem might be a recursive loop, but
a trace shows that the problem occurs before I ever enter a loop. The
error message appears at the Begin statement of a Procedure, immediately
after the Var's.

Any suggestions?

 

Re:Error 202 Stack Overflow


Quote
Scott Miller wrote:

> I am writing a program for cruise reservations, using a two dimensional
> array for cabin assignments and passenger names, inside a file of
> records. When I run it, I get a Stack Overflow error at the beginning of
> each procedure. The program compiles with no problem.

> The Help screen suggests {$M ...}, but I don't know how to use such a
> command. I tried putting it before the Program ...; line as follows:

> {$M 65536,0,655360}

> but it didn't change anything I could see.

> The Help screen also suggests the problem might be a recursive loop, but
> a trace shows that the problem occurs before I ever enter a loop. The
> error message appears at the Begin statement of a Procedure, immediately
> after the Var's.

> Any suggestions?

Post some code? It's kinda har to give some help without seeing the
code. Hmm..
If you pass an array by value, not by reference, you might get that
error.

--
- Asbj?rn / Lord Crc

http://home.sn.no/~bheid/
lord...@hotmail.com

Re:Error 202 Stack Overflow


Quote
> I am writing a program for cruise reservations, using a two dimensional
> array for cabin assignments and passenger names, inside a file of
> records. When I run it, I get a Stack Overflow error at the beginning > of each procedure. The program compiles with no problem.

> The Help screen suggests {$M ...}, but I don't know how to use such a
> command. I tried putting it before the Program ...; line as follows:
> {$M 65536,0,655360}
> but it didn't change anything I could see.
> The Help screen also suggests the problem might be a recursive loop, but
> a trace shows that the problem occurs before I ever enter a loop. The
> error message appears at the Begin statement of a Procedure,          > immediately after the Vars.
> Any suggestions?

   Yes - you've most likely declared too many local variables in the
subprogram: whatever Var declarations you made there, plus whatever
value parameters are being passed to it, plus the amount of data already
residing on the Stack (very hard to tell without seeing your program and
analyzing its execution some), plus the few bytes required to save the
state of the program for the return to the call...all that adds up to
more than 64K (in your case).
   Your solution must be to find ways to declare some of the
procedure-local data either as global, allocated on the Heap (via
pointers), and/or reduced sizes (smaller dimensions on arrays,
specific-size strings, etc.).

Re:Error 202 Stack Overflow


In article <3383714E.6...@sprintmail.com>,
Scott Miller  <Mille...@Sprintmail.com> wrote:

Quote

>The Help screen also suggests the problem might be a recursive loop, but
>a trace shows that the problem occurs before I ever enter a loop. The
>error message appears at the Begin statement of a Procedure, immediately
>after the Var's.

That's where the error appears as that is where the stack is allocated.
Try putting a line: Writeln('Sptr: ',sptr); as the first one in the
procedure and see what happens. (How many times it is called, how many
bytes is used per call etc.)

When writing recursive procedures one should avoid unnecessary
variables and keep those needed as small as possible. Also one should
avoid functions that return strings as the temporary storage used 256
bytes. Instead write a procedure that does the stuff.

In general when one asks something posting code is necessary for others
to help.

Osmo

Re:Error 202 Stack Overflow


Quote
Mike Copeland wrote:

> > I am writing a program for cruise reservations, using a two dimensional
> > array for cabin assignments and passenger names, inside a file of
> > records. When I run it, I get a Stack Overflow error at the beginning > of each procedure. The program compiles with no problem.

> > The Help screen suggests {$M ...}, but I don't know how to use such a
> > command. I tried putting it before the Program ...; line as follows:
> > {$M 65536,0,655360}
> > but it didn't change anything I could see.
> > The Help screen also suggests the problem might be a recursive loop, but
> > a trace shows that the problem occurs before I ever enter a loop. The
> > error message appears at the Begin statement of a Procedure,          > immediately after the Vars.
> > Any suggestions?

>    Yes - you've most likely declared too many local variables in the
> subprogram: whatever Var declarations you made there, plus whatever
> value parameters are being passed to it, plus the amount of data already
> residing on the Stack (very hard to tell without seeing your program and
> analyzing its execution some), plus the few bytes required to save the
> state of the program for the return to the call...all that adds up to
> more than 64K (in your case).
>    Your solution must be to find ways to declare some of the
> procedure-local data either as global, allocated on the Heap (via
> pointers), and/or reduced sizes (smaller dimensions on arrays,
> specific-size strings, etc.).

Good points. Additionally there is also the possibility of recursive
calling of routines. Still, some code would help in analyzing.

Bernd

Other Threads