Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > BASIC -auto string mirroring-... someone can explain this to me?
2015-11-13 21:18
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?
2015-11-13 21:25
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.
2015-11-13 21:25
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.. ;)
2015-11-13 21:29
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)
2015-11-13 21:34
Flavioweb

Registered: Nov 2011
Posts: 463
Oh...
Thanks a lot!
Tonight i can sleep peacefully.
=P
2015-11-14 14:26
Oswald

Registered: Apr 2002
Posts: 5094
solution: set heap size so that it doesnt overwrites other memory.
2015-11-14 14:33
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
2015-11-14 15:26
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) ;)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Freeze/Blazon
TheRyk/MYD!
Alakran_64
Chesser/Blazon
MWR/Visdom
Didi/Laxity
Guests online: 113
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.047 sec.