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: 466
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: 11523
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: 1686
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: 11523
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: 466
Oh...
Thanks a lot!
Tonight i can sleep peacefully.
=P
2015-11-14 14:26
Oswald

Registered: Apr 2002
Posts: 5127
solution: set heap size so that it doesnt overwrites other memory.
2015-11-14 14:33
chatGPZ

Registered: Dec 2001
Posts: 11523
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: 2477
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
Raf/Vulture Design
Conjuror
Didi/Laxity
TheRyk/MYD!
Apollyon/ALD
hedning/G★P
DKT/Samar/sidDivers
Shake
Airwolf/F4CG
d0c
Guests online: 254
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Cover Designers
1 Duce  (9.8)
2 Electric  (9.8)
3 Junkie  (9.6)
4 The Elegance  (9.5)
5 Mermaid  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.048 sec.