next up previous 216
Next: PSX_PUTENV - Set a new environment variable value
Up: Routine Descriptions
Previous: PSX_LOCALTIME - Convert the value returned by PSX_TIME to individual local time values


PSX_MALLOC - Allocate virtual memory

Description:
The routine allocates an amount of virtual memory specified by SIZE. The unit of SIZE is the amount of storage required to store a single character. A pointer to the allocated storage is returned in PNTR. This pointer can be passed on to other subroutines using the %VAL construct. If the storage cannot be allocated, then PNTR is set to zero, STATUS is set to PSX__NOALL and an error is reported.

Invocation:
CALL PSX_MALLOC( SIZE, PNTR, STATUS )

Arguments:

SIZE = INTEGER (Given)
The amount of virtual memory to be allocated.
PNTR = POINTER (Returned)
A pointer to the allocated storage.
STATUS = INTEGER (Given and Returned)
The global status.

Examples:

CALL PSX_MALLOC( 40, PNTR, STATUS )
CALL SUB1( %VAL(PNTR), 10, STATUS )
...
SUBROUTINE SUB1( ARRAY, N, STATUS )
INTEGER N
INTEGER ARRAY( N )
...
Allocates 40 bytes and uses this as a 10 element INTEGER array.

The call to PSX_MALLOC allocates forty bytes of storage. 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 PSX_CALLOC or 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: cnfFptr, cnfMalloc

References

Copyright
Copyright (C) 1991 Science & Engineering Research Council


next up previous 216
Next: PSX_PUTENV - Set a new environment variable value
Up: Routine Descriptions
Previous: PSX_LOCALTIME - Convert the value returned by PSX_TIME to individual local time values

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