ContentsIndexPreviousNext

6.3 Memory Management

This section discusses how ACUCOBOL-GT manages its runtime memory and what tools you have to control it. When runcbl initiates, it loads the main program into memory and starts executing it. As other programs are called, they are also loaded into memory. Once loaded, a program remains in memory until it is canceled, at which point it is removed. This allows for a full ANSI implementation of subprograms (variables retain their previous values when a subprogram is re-entered, files can be left open in a subprogram, and so forth).

Obviously, a large system can eventually occupy very substantial amounts of memory if subprograms are never canceled, particularly in menu driven systems where the master menu calls the various menu selections. To deal with this problem, two tools are available, the CANCEL verb and the IS INITIAL PROGRAM clause of the PROGRAM-ID.

When used, the CANCEL verb will remove from memory the affected subprograms. It can be very inconvenient to CANCEL every subprogram in a menu driven system however, so ACUCOBOL-GT supports an extension to the CANCEL verb to handle this case. This is the CANCEL ALL verb. When executed, a CANCEL ALL will CANCEL every subprogram that is not active. A program is active if it is either the main program or it has been called, but it has not yet exited. Executing a CANCEL ALL after a menu selection completes is an easy way to free the memory used by that program.

When specified, the IS INITIAL PROGRAM clause causes a subprogram to be automatically canceled whenever it exits. This can be used to manage memory or to ensure that VALUE clauses are set whenever a subprogram is called. Note that the compiler will automatically apply this clause to a program compiled with the "-Zi" option. This can be particularly useful when you are converting programs from RM/COBOL version 2.

In RM/COBOL, the status of a program that exits is not precisely defined. Subprograms remain in memory until either their caller exits or until inadequate memory remains to load another subprogram. This occurs at fairly unpredictable times. Most RM/COBOL subprograms are treated as if they have been canceled when they exit, since their fate in memory is unclear. By applying the "-Zi" option at compile time, the ACUCOBOL-GT programmer can simulate this behavior. Note, however, that utility subprograms that are called repeatedly should not be compiled with "-Zi", because this introduces extra overhead each time they are called. Also, any subprogram that depends on retaining variables between calls should not be compiled with "-Zi".

As a special note, RM/COBOL treats spooled print files specially in that they are not closed when a subprogram exits (all other files are closed). ACUCOBOL-GT does not treat spooled files specially, so if this feature of RM/COBOL is used, the subprogram that does this should not be compiled with "-Zi".

Other tools are available to help manage memory. Segmentation (overlays) can be used to reduce the size of a single program. This is described in section 6.5 of the ACUCOBOL-GT Reference Manual. The CHAIN verb (section 6.6 in Book 3, "Reference Manual") and the C$CHAIN library routine (Appendix I in Book 4, "Appendices") can be used to replace the running program with another program. This can conserve substantial amounts of memory. Finally, you can adjust the size of ACUCOBOL-GT's runtime buffers with the V-BUFFERS and SORT-MEMORY configuration options described in Appendix H in Book 4, "Appendices."

More:

6.3.1 External Data Items