next up previous 216
Next: PSX_SRAND - Set the seed for the random number generator
Up: Routine Descriptions
Previous: PSX_RAND - Generate a random number


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
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


next up previous 216
Next: PSX_SRAND - Set the seed for the random number generator
Up: Routine Descriptions
Previous: PSX_RAND - Generate a random number

PSX POSIX interface routines
Starlink User Note 121
P M Allan
A J Chipperfield
10 April 2003
E-mail:ussc@star.rl.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils