Concise code
ScottL
Posts: 14
Well my first project is in danger of running out of RAM on the BS2px, out of variable space and 76% on program storage. Maybe my application is too ambitious. Is there a guide like "The Elements of PBASIC style" to·advise me how to write more concise code? Tips & tricks? -Scott
Comments
·· When you say 76% of program space, are you referring to all 8 slots or just slot 0?· In terms of variables, are you making the best use of your variables and re-using them when possible?· Are you declaring the smallest variable for what you need to store?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
It may be a bit more likely to get detailed help if you would post an attachment of your code. If there is proprietary info, you could just post the area that is giving you the most trouble.
Lee
http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
When you say 76% of program space, are you referring to all 8 slots or just slot 0?· I am using the BS2px, according to the article you referenced, only the 2e,2sx and 2p have this. Does the 2px have this?
In terms of variables, are you making the best use of your variables and re-using them when possible? I removed all references to constants and replaced each occurance with the value. I also removed variables that stored intermediate values. I'll look again.
Are you declaring the smallest variable for what you need to store? I reviewed these last night but I'll look again in daylight. -Scott
p.s. code attached
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
·· The BS2px has the same memory features as the BS2p, it's just faster and has 2 additional commands.· Otherwise it is a BS2p.· Removing references to constants doesn't save any memory.· You should keep your constants as they're only compiled when referenced in the code and make it cleaner and easier to follow.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
In Bank 0 you place the main loop and reading sensors.
In Bank 1 you place everything to do with the LCD.
Variables needed by both parts can be placed in Scratchpad RAM.
It'll take a bit of restructuring, but it will allow for easier expansion later, when you decide to add temperatures, liquid-levels, GPS....
Oh, and read up on Multibank programming in Nuts & Volts Column# 87 Multi Bank Programming
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...