This article was previously published under Q62215
This article has been archived. It is offered "as is" and will no longer be updated.
If a compiled Basic program is linked with a large or huge memorymodel FORTRAN routine that uses either CHARACTER data or the FORTRANREAD or WRITE statements, the Basic program will not be able to accessthe far heap.
To avoid this problem, link only to FORTRAN routines compiled in the mediummemory model.
FORTRAN routines placed in a Quick library will work correctly, evenif the FORTRAN is compiled in the large or huge memory model.
A number of symptoms can indicate the problem above. Here are two:
Basic function FRE(-1), which should return the total available memory (far heap + data segment), returns the same amount of space as the available data segment space. The amount of available data segment space can also be obtained by FRE(0), and if Basic cannot access the far heap due to the above problem, the amount returned by these two functions will be equal.
Basic will report "Out of memory" when trying to dimension a $DYNAMIC array larger than the remaining space in the data segment. Since Basic cannot access the far heap, the free portion of the data segment is the only available memory, and memory will be exhausted if the array is larger than the space remaining in the data segment.
Below are two FORTRAN examples that demonstrate the problem. Program 1shows a FORTRAN call without I/O statements. Program 2 shows the sameprogram with one WRITE statement included.
NOTE: The Basic program does not even have to call the FORTRANsubprogram; it is the allocation of the FORTRAN data space that causesthe error.
To compile the FORTRAN.OBJ, use the following commands:
To compile the Basic.OBJ, use the following command:
BC /A /O /AH BASPROG.BAS;
Then, link the files together as follows:
LINK /NOE BASPROG+FORPROG1,PROG1; 'for program #1 LINK /NOE BASPROG+FORPROG2,PROG2; 'for program #2
To run the programs, type either PROG1 or PROG2.
'-------BASPROG--------------------------- DECLARE SUB ForSub () DIM heap%(2048) COMMON /nmalloc/ heap%() PRINT "In Basic...memory = "; FRE(-1) CALL ForSub PRINT "Back in Basic. memory = "; FRE(-1) END
FORTRAN Program 1
subroutine forsub RETURN END
FORTRAN Program 2
subroutine forsub WRITE(*,*)'This is the FORTRAN program.' RETURN END
In Basic...memory = 416968 Back in Basic. memory = 416968
In Basic...memory = 53992 Back in Basic memory = 53992
If the above example is used, but the FORTRAN compiler is instructedto use the medium memory model (/AM instead of /AL) and the libraryMLIBFORE is linked instead of LLIBFORE, the program will workcorrectly.