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
Announcement
Collapse
No announcement yet.
PRINT AT
Collapse
X
-
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"
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"
Alan
------------------
Alan C. Earnshaw
Information Management Systems, Inc.
http://www.infoms.com
Leave a comment:
-
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
Leave a comment:
-
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 ?
Tags: None
Leave a comment: