Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

PRINT AT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PRINT AT

    FUNCTION AT(BYVAL row AS INTEGER, BYVAL col AS INTEGER) AS STRING
    LOCATE row, col
    END FUNCTION
    Print AT(20,2);"THE CODE"
    is the same as

    Locate 20,2: Print "THE CODE"

    The above code is a shortcut to the Locate x,yrint "Hello"

    However the resulting EXE is larger using this method.

    My program is out of memory and I need to reduce the size, is there any way to streamline the above method ?


  • #2
    Using a FUNCTION does reduce the size of the EXE, as long the FUNCTION is used more than a couple of times.

    When you say, "Out of Memory" do you mean you get a run-time error #7 (out of memory)? Or do you mean the code does not fit in the IDE? Or you get a compile time error for too much string literal space?

    If you are facing an "out of memory" run-time error #7, you should know that code size has nothing to do with that, and whatever your problem is, you need to look elsewhere.

    Show us the actual error/status message and we'll have some ideas for you.

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Actually, Michael, using a one-line function to replace an internal PowerBASIC statement does use more memory (for the code; the actual usage of data space will be negligible).

      You get extra code added to the program for the function itself, and you also have more code at each call to the function (probably 32 - 64 bytes). I presume this code pushes parameters onto the stack, handles the return value, etc.

      In a brief test using PowerBASIC 3.2 and the provided sample code,

      Code:
      LOCATE 20,2 : PRINT "THE CODE"
      generates 320 bytes of code (according to the Compile/Get Info menu in the IDE).

      The one-line function version (edited slightly here):

      Code:
      FUNCTION ATA(BYVAL row%, BYVAL col%) AS STRING
        LOCATE row%, col%
      END FUNCTION
      PRINT ATA(20,2); "THE CODE"
      generates 384 bytes of code. If I add one more LOCATE/PRINT pair and one more call to the ATA function to the programs (printing the same literal string), the code sizes go to and 336 and 416 bytes. One added 16 bytes, the other added 32 bytes. In a program that makes hundreds of these calls, that will make a difference.

      Alan


      ------------------
      Alan C. Earnshaw
      Information Management Systems, Inc.
      http://www.infoms.com
      Alan C. Earnshaw
      Information Management Systems, Inc.
      http://www.infoms.com

      Comment


      • #4
        On reflection, using all literals (e.g., LOCATE Literal, Literal: PRINT Literal), would have to result in smaller code. In fact, that's the method used by the IBM mainframe COBOL compiler to optimize: if a statement uses datanames which are constants (that is, never altered elsewhere in the program), that compiler converts to 'in-line' format.

        I so rarely use literals like that, though. At worst, I use equates, otherwise I use datanames. Lots easier to maintain that way.

        MCM

        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X