Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) 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: 442
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: 11100
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: 1665
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: 11100
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: 442
Oh...
Thanks a lot!
Tonight i can sleep peacefully.
=P
2015-11-14 14:26
Oswald

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

Registered: Dec 2001
Posts: 11100
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: 2053
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
niallquinn
WVL/Xenon
Kickback
MightyAxle
Guests online: 173
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Carrion  (9.8)
2 Joe  (9.8)
3 Duce  (9.8)
4 Mirage  (9.7)
5 Facet  (9.7)

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