Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:18 07 Sep 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : String magic: String$ LENGTH oddities.

Author Message
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1769
Posted: 10:55pm 07 Mar 2025
Copy link to clipboard 
Print this post

Maybe someone has an explanation? (MMBasic Pico 2 V60002b14)

Clear
Print "Clear."
Print MM.Info(Heap),"Dim test0$"
Dim test0$
Print MM.Info(Heap)
Clear
Print "Clear."
Print MM.Info(Heap),"Dim test0$"
Dim test0$
Print MM.Info(Heap)

Clear
Print
Print "Clear. Heap: ";
Print MM.Info(Heap)
Print

Clear
Print "Clear. Heap: ";MM.Info(Heap)

Clear
Print
Print "Clear. Heap: ";
Print MM.Info(Heap)
Print

Print
Dim test1$ length 1
Print MM.Info(Heap),"Dim test0$ length 1"
test1$="A"
Print
Dim test2$ length 2
Print MM.Info(Heap),"Dim test2$ length 2"
test2$="AB"
Print
Dim test3$ length 3
Print MM.Info(Heap),"Dim test3$ length 3"
test3$="ABC"
Print
Dim test4$ length 4
Print MM.Info(Heap),"Dim test4$ length 4"
test4$="ABCD"
Print
Dim test5$ length 5
Print MM.Info(Heap),"Dim test5$ length 5"
test5$="ABCDE"
Print
Dim test6$ length 6
Print MM.Info(Heap),"Dim test6$ length 6"

Print
Dim test7$ length 7
Print MM.Info(Heap),"Dim test7$ length 7"

Print
Dim test8$ length 8
Print MM.Info(Heap),"Dim test8$ length 8"

Print
Dim test9$ length 9
Print MM.Info(Heap),"Dim test9$ length 9"

End


Output:
Clear.
183808 Dim test0$
183552
Clear.
183808 Dim test0$
183552

Clear. Heap:  183808

Clear. Heap:  183552

Clear. Heap:  183808


183808 Dim test0$ length 1

183808 Dim test2$ length 2

183808 Dim test3$ length 3

183808 Dim test4$ length 4

183808 Dim test5$ length 5

183808 Dim test6$ length 6

183808 Dim test7$ length 7


183552 Dim test8$ length 8

183296 Dim test9$ length 9


If I interpret this correctly, then normal strings always "cost" 256 bytes of heap memory. While strings dimensioned with LENGTH <8 appear to be 'free' , above LENGTH 7, however, they cost the full price = 256 bytes.

This part almost surprises me more. I would not have expected the heap to be affected by the position of the print output.
Clear
Print
Print "Clear. Heap: ";
Print MM.Info(Heap)
Print

Clear
Print "Clear. Heap: ";MM.Info(Heap)

Clear
Print
Print "Clear. Heap: ";
Print MM.Info(Heap)
Print


Output:
Clear. Heap:  183808

Clear. Heap:  183552

Clear. Heap:  183808


Michael
‚My name is Ozymandias, king of kings
Look on my works, ye Mighty, and despair!‘
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and ...
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11818
Posted: 11:02pm 07 Mar 2025
Copy link to clipboard 
Print this post

  Quote  If I interpret this correctly, then normal strings always "cost" 256 bytes of heap memory. While strings dimensioned with LENGTH <8 appear to be 'free' , above LENGTH 7, however, they cost the full price = 256 bytes.


Correct
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1769
Posted: 11:10pm 07 Mar 2025
Copy link to clipboard 
Print this post

  matherp said   ... Correct

Thanks! I was very surprised.
Kind regards
Michael
‚My name is Ozymandias, king of kings
Look on my works, ye Mighty, and despair!‘
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and ...
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026