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. If the number required exceeds the maximum that can be stored in an INTEGER (about 2.1E9), them routine PSX_MALLOC8 should be used in place of PSX_MALLOC. PSX_MALLOC8 has an identical interface except that the SIZE argument is an INTEGER∗8.
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