Microsoft KB Archive/58926
Article ID: 58926
Article Last Modified on 8/16/2005
- Microsoft Visual Basic for MS-DOS
- Microsoft QuickBasic 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBasic 4.5 for MS-DOS
- Microsoft BASIC Compiler 6.0
- Microsoft BASIC Compiler 6.0b
This article was previously published under Q58926
Arrays can be stored in different places depending on array type and on whether the program is run from an .EXE file, or the VBDOS.EXE (included with Microsoft Visual Basic for MS-DOS) or QB.EXE (included with Microsoft QuickBasic for MS-DOS and Microsoft Basic Compiler for MS-DOS) environments. All nonarray (scalar) variables are always stored in the DGROUP segment.
In the VBDOS.EXE and QB.EXE environments, a static array of numeric type or fixed-length-string type must be in a COMMON or COMMON SHARED statement to be allocated in the DGROUP memory area; otherwise it will be stored in the far heap.
In an executable file (.EXE), all types of static arrays are always stored in the DGROUP area (which can be referenced with a near address).
Dynamic or static arrays of variable-length strings are always stored in DGROUP in VBDOS.EXE, QB.EXE and .EXE programs.
For a complete description of variable storage allocation, please read Pages 32 and 33 of the "Microsoft QuickBasic 4.0: Basic Language Reference", Pages 32 and 33 of the "Microsoft Basic Compiler 6.0: Basic Language Reference", or Appendix B "Memory Management" in the "Microsoft Visual Basic for MS-DOS Programmer's Guide" for version 1.0.
DGROUP is also known as the default data segment, or the near data storage area.
In summary, array storage in VBDOS.EXE or QB.EXE adheres to the following three rules:
- All $STATIC arrays in COMMON or COMMON SHARED are stored in DGROUP.
- All arrays of type variable-length string are stored in DGROUP.
- All other arrays are stored in far addresses.
Array storage in .EXE programs adheres to the following three rules:
- All $STATIC arrays are stored in DGROUP.
- All $DYNAMIC arrays of variable-length strings are stored in DGROUP.
- All other $DYNAMIC arrays are stored as far objects in the far heap.
The program below illustrates the preceding information.
' To try this example in VBDOS.EXE: ' 1. From the File mneu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program. DIM ar1(100) AS INTEGER ' REM $STATIC is the default for arrays. DIM ar2(100) AS INTEGER ' REM $STATIC is the default for arrays. COMMON SHARED ar2() AS INTEGER ' Must be in COMMON in VBDOS.EXE or QB.EXE environment to be placed ' in DGROUP. s$ = "hello" ' This is put into DGROUP. REM $DYNAMIC DIM ar3(100) AS INTEGER PRINT VARSEG(s$), VARSEG(ar1(0)), VARSEG(ar2(0)), VARSEG(ar3(0))
Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b