Shop OBEX P1 Docs P2 Docs Learn Events
Concise code — Parallax Forums

Concise code

ScottLScottL Posts: 14
edited 2006-05-16 12:46 in BASIC Stamp
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

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-15 14:40
    Scott,

    ·· 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
  • Lee HarkerLee Harker Posts: 104
    edited 2006-05-15 19:51
    Scott,
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-15 19:59
    The following article should help.

    http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-15 23:05
    I've only filled one 2K slot in all the years of the BS2 and its siblings, so there may be opportunites to save code -- but we'd have to see it to make specific recommendations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ScottLScottL Posts: 14
    edited 2006-05-15 23:18
    Thanks Chris,
    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
  • SSteveSSteve Posts: 808
    edited 2006-05-16 03:03
    Replacing constants with literal values doesn't save you any variable or code space. It only makes the code harder to understand and much harder to change. You should undo that particular change.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-16 03:16
    You have a lot of redundant code in the Write_X subroutines -- you might consider offloading those values into tables and then indexing through with an offset.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-16 03:28
    ScottL said...(trimmed)
    I am using the BS2px, according to the article you referenced, only the 2e,2sx and 2p have this. Does the 2px have this?
    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.
    Scott,

    ·· 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
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-05-16 10:23
    Split the code in two parts:

    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...
  • ScottLScottL Posts: 14
    edited 2006-05-16 12:46
    Thanks guys, I really appreciate your help. -Scott
Sign In or Register to comment.