Dynamic Memory

It is possible to examine the values of dynamically allocated memory. These are treated as a Fortran common block, with all of the Mem arrays equivalenced to a single array. The relevant Fortran code generated is shown in Example D.1.


The VAX/VMS debugger permits examining the Mem arrays. Keep in mind the manner in which the array was allocated, however. The pointer is an arbitrary offset into virtual memory. The elements of your array are located relative to the pointer. The debugger will not know the size of the array, but you can specify a range of elements to examine. Once the pointer is dereferenced by passing to a procedure, it is treated as a normal Fortran array. However, be particularly careful of arrays declared in procedures with ARB. ARB is a macro that translates into a very large number. If you examine an array declared ARB without specifying a range of elements, the debugger will try and list what it thinks are all of the elements of the array. Remember to specify a range of array elements.


In the Unix dbx debugger, it is a bit more tedious to examine the contents of a dynamically allocated arrays. You need to specify the memory location (pointer address) and the data type to display. For example, if a pointer to Memr is in a variable called line, then the following dbx command will display the first element:

print (line-1)*4/f 
To look at the nth element, add n to the word location:

print ((line-1)*4+10)/f 
will show the 10th element. The following dbx initialization file defines command aliases to help examine contents of the Mem buffers. It may be placed in the file .dbxinit in the Unix root directory.

The commands are used by specifying the symbol name of the memory pointer. For example if the SPP code contained:

        call malloc (buf, npix, TY_REAL) 
        call myproc (Memr[buf], npix) 
Then you could examine the first element of the memory buffer pointed to by buf with the dbx command:

        memr buf

Generated with CERN WebMaker