Microsoft KB Archive/32434

“Load Failure”; Memory Fragmentation Calling Subprogram

PSS ID Number: Q32434 Article last modified on 11-16-1992

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: It is possible to create memory fragments when calling subprograms. The following error messages can indicate an out of memory/fragmentation problem: 01 - Insufficient buffer space (Not enough memory to allocate file buffer) 198 - Load failure (Insufficient memory for program) Memory fragmentation can occur in some programs due to the run-time system allocating 32K on the first OPEN of a non-ISAM file and 64K on the first OPEN of an ISAM file. Note: The +G run-time switch (the small-buffer switch) does not affect the memory allocations for the file buffer region that is designated on the first file OPEN. For more detailed information about memory fragmentation due to subprograms’ calls, CHAINing, and file buffer allocation, query on the word COBCHAIN to find the application note “Strategy for Successful CHAINing in COBOL 3.00.”

More Information: To avoid the potential memory fragmentation caused by dynamically CALLing or CHAINing to subprograms and OPENing a file, it is best to statically LINK your main driver program with ADIS.OBJ, ADISINIT.OBJ, ADISKEY.OBJ, and IXSIO.OBJ (instead of letting them be CALLed dynamically), as in the following example: LINK driver+ADIS+ADISINIT+ADISKEY+IXSIO; The following are the two types of CALLs in Microsoft COBOL Versions 3.00 and 3.00a: 1. Calling a literal (STATIC call). The following is an example: CALL “FRED” USING PARM1… 2. Calling a variable (DYNAMIC call). The following is an example: 01 FRED PIC X(10) VALUE “SUB1”. CALL FRED USING PARM1. When calling dynamically, you must ensure that the PROGRAM-ID clause agrees with the CALLed filename, as follows: CALL “FRED”. FRED.EXE is the filename and FRED.COB contains one of the following: IDENTIFICATION DIVISION. PROGRAM-ID. FRED. or IDENTIFICATION DIVISION. PROGRAM-ID. FRED INITIAL. (“INITIAL” initializes WORKING-STORAGE variables each time FRED is CALLed.) When CHAINing, it is best to CHAIN back to the driver program prior to CHAINing to another program. The following chart shows a typical memory usage that might result in memory fragmentation for a COBOL Version 3.00 program at run time: +—————————+ | FRED.EXE | | (Driver) | |—————————| | SUB1.EXE | | | | OPEN Sequential File | | OPEN ISAM File | | | |—————————| | 32K Buffer | |—————————| | 64K Buffer | |—————————| | | | Free Memory | | | | | | | +—————————+ The following run-time organization is suggested to avoid memory fragmentation problems when calling subprograms and opening files. In the case below, the driver program FRED.OBJ must be statically linked to the necessary I/O routines, as follows: LINK FRED+ADIS+ADISINIT+ADISKEY+IXSIO; +—————————+ | FRED.EXE | | (Driver) | | | | Driver is linked with: | | ADIS | | ADISINIT | | ADISKEY | | IXSIO | | | | OPEN Sequential File |—>–+ | OPEN ISAM File | | | | | |—————————| v | 32K Buffer | <– DISPLAY SPACES ON CRT will |—————————| open ADISCTRL and effectively | 64K Buffer | allocate this buffer. |—————————| | SUB1.EXE | |—————————| | | | Free Memory | | | | | +—————————+

Copyright Microsoft Corporation 1992.