| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
BASIC -auto string mirroring-... someone can explain this to me?
Why if i run this code:
10 get a$
20 if a$=""then10
30 x=x+1
40 poke 20480+x,asc(a$)
50 goto 10
and then type "test for csdb !!!!" i have:
.,5000 @TEST FOR CSDB !!!!m@@@@@@@@@@@@
.,9fe0 @@@@@@@@@@@@@m!!!! BDSC ROF TSET
into memory?
What produces the "mirrored" string at $9FFF? |
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
every time a string is created, or assigned, it will be put on the string heap - which grows downwards from the end of the basic memory. that happens until the heap fills up the entire "free" basic memory, then the infamous "garbage collection" will kick in and clean up the mess. |
| |
Perff Administrator
Posts: 1679 |
WAAY long time since I coded basic on the C64, but if I remember correctly variables values are stored from $9fff and down.
So when a$ is assigned a value from the "get" command, it stored backwards from $9fff. Why it dosn't overwrite the old values I don't know.
And this is just my best guess. :)
Edit: Damn. Beaten by seconds.. ;) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
it doesnt overwrite the old value because the length of the string is not constant, so it always has to allocate enough memory for the entire string. (and it only does that for strings, not numerical variables - because those have a fixed length) |
| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
Oh...
Thanks a lot!
Tonight i can sleep peacefully.
=P |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
solution: set heap size so that it doesnt overwrites other memory. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
either that, or create a huge array to allocate the memory, and then use that, instead of directly poking into arbitrary memory blocks |
| |
TheRyk
Registered: Mar 2009 Posts: 2244 |
or don't use strings at all (which of course would bring the next logical consequence, not using BASIC at all) ;) |