| 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 ... |