Microsoft KB Archive/45851

Memory Management in QuickBASIC 4.00/4.50, BASIC Compiler 6.00 PSS ID Number: Q45851 Article last modified on 05-02-1991 PSS database name: B_QuickBas

4.00 4.00b 4.50

MS-DOS

Summary:

A file is available in the Software/Data Library that describes how to take better advantage of QuickBASIC’s data types and modular code constructs to better manage the data and code in your programs. This article applies to Microsoft QuickBASIC versions 4.00, 4.00b, and 4.50 for MS-DOS and to Microsoft BASIC Compiler versions 6.00 and 6.00b for MS-DOS.

This file can be found in the Software/Data Library by searching for the word QB4MEMAN, the Q number of this article, or S12336. QB4MEMAN was archived using the PKware file-compression utility.

This information can also be obtained as an application note titled “Memory Management in QB 4.x” by calling Microsoft Product Support Services.

More Information:

This application note covers the following topics:

  Code management   Modular programming   What goes at the module level in a support module   COMMON, COMMON SHARED, SHARED, DIM SHARED    Data management   $DYNAMIC and $STATIC metacommands   Huge arrays </li></ol> </li></ol>

Appendix A contains a code example that illustrates the topics covered in this application note.

Appendix B explains the .MAP file created when the Appendix A program example is linked. You can use the LINK map to determine how close each module is to approaching the 64K code limit and how close the .EXE program’s static variables are getting to the 64K limit in the DGROUP.

Appendixes C and D describe in detail the memory mapping for running programs in the following three different environments: the QB.EXE editor, a compiled .EXE program using the run-time module, and an .EXE compiled with the stand-alone option.

Definitions
A “module” is defined as an individual source file containing BASIC procedures.

“Module-level code” is defined as the statements within a module that are outside a SUB…END SUB, FUNCTION…END FUNCTION, or DEF FN..END DEF definition block.

A “support module” is a source file, separate from the main module, that contains additional SUB or FUNCTION procedures.

Memory Diagram
The following diagram summarizes how QuickBASIC compiled programs are loaded into memory at run time:

High Memory (640K maximum) _____________    |           |   The far heap stores dynamic arrays. The far |  (Far)   |     heap consists of the rest of high memory |  Heap    |     available after MS-DOS and the BASIC |          |     program's DGROUP segment and code __________________| segment(s) are allocated. | | The stack is used to store temporary data, DGROUP| Stack | such as variables that are passed to a | | subprogram procedure. The default stack Up to |___________| size is 2K. 64K | | The DGROUP (default data segment) is used | (Near) | to store all static arrays, strings, | Data | simple variables, and the stack. DGROUP ___________________ can be up to 64K in size. : _____________ | Code | The code segments store the executable code. | Segments | Each module can have up to 64K for its _____________ code segment. Low Memory

Please refer to the complete application note for more detailed information.

Copyright Microsoft Corporation 1991.