I am not a math whiz. I recall reading somewhere that intergers (A%) use less memory than normal variables (A).
What is the difference in memory? Is that difference negated by the longer program?
For example, maybe it saves 3 bytes by not saving a decimal. What if I use the variable A% five times in a program? Wouldn't that cost me five extra bytes as opposed to using A just from the extra memory the %-sign uses in line memory?
I suppose if I run out of the 26 letter variables, A% is more efficient than A2 or AA. But, is the above true? I am confused.
Intergers
Moderator: Moderators
- Mike
- Herr VC
- Posts: 4838
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
That isn't necessary here, anyway.I am not a math whiz.
You must tell the "savings" in programm space apart from those in variable space. Same applies to execution time.
All references to an integer variable need the extra byte for the % sign within the BASIC program.
As long as you use a single integer there is *no* savings in variable space, as all variables - be it a real number, an integer number, a string descriptor[*], or a function descriptor - occupy 7 bytes. The data for an integer needs 2 bytes for the variable name, 2 bytes data, and 3 bytes are wasted.
Contrary to this, if you use an array of integers (say, DIM M%(2,2)) the array *will* need only 2 bytes per element. The savings are here.
Regards execution time: Internally, all calculations are done with real numbers (in CBM BASIC). If the interpreter needs to read an integer variable (single or in an array), it must be converted to real. Same applies to storing. So integers cost you additional execution time.
Greetings,
Michael
[*]: Strings of course need their own space at the end of BASIC memory.