CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2133
Posted: 11:08am 11 Mar 2025
To be clear about this - my point of reference for all this is Micromite Mk2 (PIC32MX170-based). The graphic above shows the VARTBL memory layout for that 'mite, which does not use hashed variables and is unlikely ever to do so - being considered "finished" and updates to the firmware are for serious bugs only. Each variable there takes 64 bytes in the table - I can account for around 50 of them so not that bad at all and a small price to pay to keep things a nice "CPU-sized" number.
The "worst waste" is using undimensioned strings - they are all 255 bytes long - even
A$="Hello World!"
and the syntactically accepted LENGTH is ignored for single variables. I think this extends to all 'mite flavours - anyone?
You can make things a bit better if you are REALLY low on RAM by making sure all your string variables are part of an array and then using LENGTH, but it doesn't make for easy reading and there is a tiny speed penalty. Using a CONST to identify specific members of the array can help, but it's an awful faf and arguably just moving the problem to flash storage from RAM (but this does save 500 bytes):
'very convuluted but you get the idea Const Greeting=1 Const Goodbye=2
Option Base 1
Dim m$(2) =("wotcha","tata") Length 10
Print m$(Greeting)
Print m$(Goodbye)
In all honesty, I have yet to be seriously hampered by this and it really doesn't stop me sleeping. Birds. Birds stop me sleeping.