Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug: String Slicing (*solved*)
#2
This is a bit odd... Confusedhock:

The 1st time the program runs ok (at less in the new version 1.2.1, which in fact changes the heap memory scheme).

Note:
Quote:In current releases, once you return to basic, the initialization routines are corrupted, so you can't enter the program again using RANDOMIZE USR. You have to reload it. This is because I use a scheme to save memory that once initialized, uses that memory for variables (so it gets corrupted).
The new initialization scheme works in a different way, so you can re-run the program (e.g. by using RANDOMIZE USR 32768) as much as you want.

Back to the topic: I compiled with v.1.2.1. I don't see any crash. Reruning the program with RANDOMIZE USR effectively works too! So test the release 1.2.1 (I'll put it in a few minutes) and tell me if it works for you.

The Problem:
String variables a$ and p$ keep the previous execution values. So when you do p$ = a$(...), the previous value of p$ is still in memory, pointing to a heap location that gets corrupted, because on each runs the heap is initialized and then the program tries to "release" the previous value of p$ (which does not exist anymore). Hmmmm. If this is too technical, forget it... Just tried to explain you the reason.

Now exiting to BASIC does preserve everything, so initializing the program works, but it preserves all the variables. :!:
Remember this is like in C. Declaring an initialized variable does not mean it is assigned on each execution:

Code:
// In C
int a = 1; /* this just means to reserve a memory location containing 01 00 00 00 */

// In ZX BASIC
DIM a as Integer = 1 : REM The same

DIM b
LET b = 0  : REM This ENSURES b is assigned 0 on each execution
So, basically, if you expect your program to be run more than once, use LET. Otherwise, just initialize the variable with DIM (faster and saves some bytes).
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)