Handling ImageWriter LQ/LaserWriter Printing Problems in BASIC (33630)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple 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, "Out of Heap Space," "Device I/O," 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 ("LPT1:" or "LPT1:PROMPT") 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 "Out of Memory" 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:

  1. The following technique CHAINs, then prints:

    1. Copy the variables to be printed to a disk file or resource (or put them in a COMMON block)
    2. 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 "Out of Memory" error) to increase heap space before opening the printer. (CLEAR erases anything in COMMON.)
    3. OPEN "LPT1:" or "LPT1:PROMPT" FOR OUTPUT AS #n and send output with PRINT#n, WRITE#n, or WINDOW OUTPUT#n. CLOSE sends the output to the printer.
    4. CHAIN back to the first program.
  2. The following technique stores variables, CLEARs, then prints:

    1. 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].
    2. Use CLEAR,xxx to shrink BASIC's data space and increase heap.
    3. Open the "LPT1:" or "LPT1:PROMPT" device and send the data to the printer. Then CLOSE the printer device.
    4. Use another CLEAR,yyy to reallocate data space.
    5. Restore the data your program needs and continue.
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 "apl" programs compiled in Macintosh QuickBASIC currently does two MoreMasters traps.)

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB33630