PSX_REALLOC

Change the size of an allocated region of virtual memory

Description:

The routine changes the size of the region of virtual memory pointed to by PNTR. The new size may be larger or smaller than the old size. The contents of the object pointed to by PNTR shall be unchanged up to the lesser of the old and new sizes.

Invocation

CALL PSX_REALLOC( SIZE, PNTR, STATUS )

Arguments

SIZE = INTEGER (Given)
The new amount of virtual memory required. If the number required exceeds the maximum that can be stored in an INTEGER (about 2.1E9), them routine PSX_REALLOC8 should be used in place of PSX_REALLOC. PSX_REALLOC8 has an identical interface except that the SIZE argument is an INTEGER∗8.
PNTR = POINTER (Given and Returned)
A pointer to the allocated storage
STATUS = INTEGER (Given)
The global status

Examples:

CALL PSX_MALLOC( 20, PNTR, STATUS )
...
CALL PSX_REALLOC( 40, PNTR, STATUS )
CALL SUB1( %VAL(PNTR), 10, STATUS )
...
SUBROUTINE SUB1( ARRAY, N, STATUS )
INTEGER N
INTEGER ARRAY( N )
...
Allocate 20 bytes of storage, then extend it to 40 bytes.

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_NB <T > 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).

Notes:

External Routines Used

cnf: cnfCptr, cnfFptr, cnfMalloc, cnfRegp, cnfUregp

References

Copyright

Copyright (C) 1991 Science & Engineering Research Council