Microsoft KB Archive/33630

= Handling ImageWriter LQ/LaserWriter Printing Problems in BASIC =

Article ID: 33630

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q33630



SUMMARY
Heap-space memory limits may be exceeded when printing to the Apple ImageWriter LQ or the Apple LaserWriter printer from a Macintosh QuickBASIC (or earlier BASIC) interpreted or compiled program. Exceeding heap space can result in System Error 25, &quot;Out of Heap Space,&quot; &quot;Device I/O,&quot; or other memory-related errors.

Below are techniques to work around this memory management limitation.



MORE INFORMATION
The simplest way to increase the heap before printing to an Apple LaserWriter is to use the FRE(-1) function. FRE(-1) forces BASIC to make the Macintosh's memory manager compact (and unfragment) heap-space memory. Invoke the FRE(-1) function before the OPEN of the printer device (&quot;LPT1:&quot; or &quot;LPT1:PROMPT&quot;) as in the following example:   PRINT FRE(-1) Also, the standard way to allocate more heap space for the printer is to execute a CLEAR,xxx statement once at the top of your program (where xxx is a data size as small as possible without getting an &quot;Out of Memory&quot; error).

In some larger programs, the best way to avoid printing problems is to CHAIN or RUN to a small program that does all printing and then CHAIN or RUN back to the first program.

For large memory-intensive programs, Microsoft recommends one of the following memory-management schemes for printing to the LaserWriter:

 The following technique CHAINs, then prints:

 Copy the variables to be printed to a disk file or resource (or put them in a COMMON block) CHAIN to a special program that prints the stored variables. If no data is passed in COMMON, the CHAINed-to program can execute a CLEAR,xxx statement (where xxx is a data size as small as possible without getting an &quot;Out of Memory&quot; error) to increase heap space before opening the printer. (CLEAR erases anything in COMMON.) OPEN &quot;LPT1:&quot; or &quot;LPT1:PROMPT&quot; FOR OUTPUT AS #n and send output with PRINT#n, WRITE#n, or WINDOW OUTPUT#n. CLOSE sends the output to the printer. CHAIN back to the first program. </li> The following technique stores variables, CLEARs, then prints:

 Copy the variables that you want preserved to a disk file or into a resource [since the CLEAR,xxx in step (b) erases all variables].</li> Use CLEAR,xxx to shrink BASIC's data space and increase heap.</li> Open the &quot;LPT1:&quot; or &quot;LPT1:PROMPT&quot; device and send the data to the printer. Then CLOSE the printer device.</li> Use another CLEAR,yyy to reallocate data space.</li> Restore the data your program needs and continue.</li></ol> </li></ol>

Programmers can also use the ToolBox interface to purge and compact memory before the OPEN. Programs that make heavy use of Macintosh features should try a couple of MoreMasters toolbox calls at the beginning of the program. (The start-up code in &quot;apl&quot; programs compiled in Macintosh QuickBASIC currently does two MoreMasters traps.)

Additional query words: BasicCom MQuickB

Keywords: KB33630

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.