Different Ways Arrays Can Be Stored in Basic

ID: Q58926


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
  • Microsoft QuickBASIC for MS-DOS, versions 4.0, 4.0b, 4.5
  • Microsoft BASIC Compiler for MS-DOS and MS OS/2, versions 6.0, 6.0b


SUMMARY

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.


MORE INFORMATION

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:

  1. All $STATIC arrays in COMMON or COMMON SHARED are stored in DGROUP.


  2. All arrays of type variable-length string are stored in DGROUP.


  3. All other arrays are stored in far addresses.


Array storage in .EXE programs adheres to the following three rules:
  1. All $STATIC arrays are stored in DGROUP.


  2. All $DYNAMIC arrays of variable-length strings are stored in DGROUP.


  3. All other $DYNAMIC arrays are stored as far objects in the far heap.


Program Example



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

Keywords :
Version : MS-DOS:1.0,4.0,4.0b,4.5; :6.0,6.0b
Platform : MS-DOS
Issue type :


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.