VMS Help
PASCAL, Predeclared Routines, Dyn Alloc
*Conan The Librarian (sorry for the slow response - running on an old VAX)
|
|
Compaq Pascal provides dynamic allocation routines for the
creation and use of pointer variables. Use pointer variables
and dynamic allocation routines to create linked data
structures.
The ADDRESS function returns a pointer value that is the address
of the parameter.
Syntax:
ADDRESS( x )
The parameter 'x' can be a variable of any type except a
component of a packed structured type. A compile-time warning
results if 'x' is a formal VAR parameter, a component of a
formal VAR parameter, or a variable that does not have the
READONLY or VOLATILE attribute.
A pointer can only refer to a VOLATILE variable or a variable
allocated by the NEW procedure.
The DISPOSE procedure deallocates memory for a dynamic variable.
Syntax:
DISPOSE( p )
The parameter 'p' is a pointer variable. The 't' parameters are
constant expressions that match the corresponding 't' parameter
used in the call to the NEW procedure that allocated the memory.
If you use 't' parameters in a call to NEW, you must specify the
same 't' parameters in the call to DISPOSE. If you allocated
memory using d parameters, just specify the pointer variable to
the corresponding DISPOSE call.
The DISPOSE procedure deallocates the object to which the
pointer variable points. You cannot call DISPOSE more than once
for the same dynamic variable.
The IADDRESS function returns an INTEGER_ADDRESS value that
refers to a the address of either a VOLATILE parameter or a
routine, and does not generate compile-time warnings (as does
the ADDRESS function). The IADDRESS function is commonly used
for constructing arguments for system services of the VMS
operating system.
Syntax:
IADDRESS( x )
The parameter 'x' can be of any type except a component of a
packed structured type or a routine name. The parameter 'x' can
be a variable, parameter, routine, or constant-expression. When
IADDRESS is used on constant-expressions, the returned address
is valid for the remainder of the program. Two calls to
IADDRESS with the same constant may not return the same address.
Note that the Compaq Pascal compiler automatically assumes that
all pointers refer either to dynamic variables allocated by the
NEW procedure or to variables that have the VOLATILE attribute;
therefore, you should use utmost caution when using the IADDRESS
function. This function does not generate compile-time
warnings.
The NEW procedure allocates memory for the dynamic variable to
which a pointer variable refers. The value of the newly
allocated variable is set to the initial value of the base type
if defined; otherwise, the value of the variable is undefined.
Syntax:
NEW( p [[, {t1,...,tn | d1,...,dn} ]] )
The parameter 'p' is a pointer variable.
The parameters 't1,...,tn' are constant expressions of an
ordinal type that represent nested tag-field values, where 't1'
is the outermost variant.
If the object of the pointer is a non-schema record type with
variants, then you have two ways of allocating memory. If you
do not specify 't' parameters, Compaq Pascal allocates enough
memory to hold any of the variants of the record. If you do
specify 't' parameters, then Compaq Pascal allocates enough
memory to hold only the variant or variants that you specify.
Since the 't' parameters cause Compaq Pascal to allocate memory
for the variant alone and not for the whole record, you cannot
assign or evaluate the record as a whole; you can assign and
evaluate only the individual fields. Also, a call to NEW does
not set the tag fields of a variant record.
The paramters 'd1,...,dn' are compile-time or run-time ordinal
values that must be the same type as the formal discriminants of
the object.
If the object of the pointer is of an undiscriminated schema
type, you must specify a 'd' parameter for each of the formal
discriminants of the schema type. The 'd' parameters
discriminate the schema type in much the same way as actual
discriminants in a discriminated schema. Compaq Pascal bases
the size of the allocation on the value of the 'd' parameters.
If the object is a schema record type, then you must use 'd'
parameters; you cannot use 't' parameters or a combination of
the syntaxes. If the schema record type contains a variant
(which depends on one of the formal discriminants) then the 'd'
parameter discriminates the schema, determines the variant, and
allows Compaq Pascal to compute the necessary size of the
allocation.
Note that if you specify 't' parameters to the NEW procedure,
you must specify the same 't' parameters to the DISPOSE
procedure that deallocates memory for the corresponding
variable.
[legal]
[privacy]
[GNU]
[policy]
[netiquette]
[sponsors]
[FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.