Re: Memory Error


[Prev][Next][Index][Thread]

Re: Memory Error



Hello,

You probably have something like this somewhere:

If something
Then
...
If something else
Goto A
...
Goto B
End

The problem is the way the calc runs loops and if/thens. Here is
simplified version of why it works (because I don't know or care about
the details):

Everytime the calc reaches a "if/then", it adds a value to a
stack(something it uses to know where to go during program execution,
a list of memory addresses, I figure). When it reached an "end", it
removes it. If you keep adding tokens without removing them, your
stack grows, and grows, and grows... 'til you know what.

The solutions:

1-Don't use gotos in loops or after if/then. Don't use Gotos at all if
you can, they're _really_ slow and often cause these kinds of
problems. With a little bit of creativity, you can do almost anyhing
with the different kinds of loops.

2-Get around the problem by putting an End after your label:

...
Lbl A
End
....

This will only work if the section of code after the label is _always_
called from inside a loop or if/then thingie. Else, you get a syntax
error. This is relatively rare because people usually prefer to use
subprograms in these cases, it's simpler and faster.

3-What you do if you can't avoid the goto statement and the block of
code is accessed in diferent ways:

Instead of just putting your label, do this:

If 0
Then
Lbl A
End

Simple, isn't it :-) It slows stuff down a tiny bit, but testing
wether 0 is equal to 0 doesn't take very long...

I'm hoping this was understood, and that it helped,

Just let me say it again, _don't_ use goto's unless you are positive
you can take care of MEM errrors and you are ready to sacrifice a lot
of speed! I have never found a program that couldn't be written
without using labels except for changing between different parts of
the prog (Main menu, options menu and game engine, for example)

Why is it so slow? Because everytime the calc finds a goto, it starts
searching the prog from that point on for the right label, when it
reaches the end it starts at the beginning. In very small programs,
this doesn't matter much because the search time is short, but it gets
a lot longer bery fast.

That's all I have to say,

Philipp Keller

Sim CEO <simceo@aol.com> wrote in message
19990115223839.07042.00001668@ng-fr1.aol.com">news:19990115223839.07042.00001668@ng-fr1.aol.com...
>I made a game on the TI-83, which is an arena fighting game, and it
keeps going
>back through the same thing over and over, not in repeat loops but in
label
>loops if you want to put it that way. My friend was testing the game,
because I
>finally got it to function properly, when after around 100 turns the
calculator
>siad "Memory Error" and the program stopped. How do I avoid this
error?


References: