Change the size of an allocated region of virtual memory PSX_REALLOC
The call to PSX_MALLOC allocates twenty bytes of storage. The subsequent call to PSX_REALLOC extends this area to forty bytes. The pointer to this storage is then passed to subroutine SUB1, where it is accessed as an array of INTEGERs. We assume SUB1 returns without action if STATUS is bad.
Note that in this case the program needs to know that an INTEGER variable is stored in four bytes. This is not portable. In such a case it is better to use the symbolic constants NUM_NBT defined in the file PRM_PAR to determine the number of bytes per unit of storage. (See SUN/39 for a description of these constants).
Storage allocated by PSX_REALLOC should be returned by a call to PSX_FREE when it is no longer needed.
PNTR is declared to be of type POINTER. This is usually represented in FORTRAN as an INTEGER, although any type that uses the same amount of storage would be just as good. The pointer will have been registered for C and FORTRAN use according to the scheme described in SUN/209, allowing its use where pointers are longer than INTEGERs. For portability, the construct %VAL(CNF_PVAL(PNTR)), rather than simply %VAL(PNTR), should be used to pass the pointer to the subroutine. Function CNF_PVAL is described in SUN/209 Section ‘Pointers’.
If SIZE is zero, then the space pointed to by PNTR is freed.
If the space that PNTR pointed to has been deallocated by a call to PSX_FREE (or to PSX_REALLOC with SIZE = 0), then it is undefined whether the pointer can subsequently be used by PSX_REALLOC. Consequently this should not be attempted, even though it will work on some machines.
POSIX standard (1988), section 8.1
ANSI C standard (1989), section 4.10.3.4